Esempio n. 1
0
  public synchronized void postAnalyticsEvent(TiAnalyticsEvent event) {
    if (!collectAnalytics()) {
      if (DBG) {
        Log.i(LCAT, "Analytics are disabled, ignoring postAnalyticsEvent");
      }
      return;
    }

    if (DBG) {
      StringBuilder sb = new StringBuilder();
      sb.append("Analytics Event: type=")
          .append(event.getEventType())
          .append("\n event=")
          .append(event.getEventEvent())
          .append("\n timestamp=")
          .append(event.getEventTimestamp())
          .append("\n mid=")
          .append(event.getEventMid())
          .append("\n sid=")
          .append(event.getEventSid())
          .append("\n aguid=")
          .append(event.getEventAppGuid())
          .append("\n isJSON=")
          .append(event.mustExpandPayload())
          .append("\n payload=")
          .append(event.getEventPayload());
      Log.d(LCAT, sb.toString());
    }

    if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_ENROLL) {
      if (needsEnrollEvent) {
        analyticsModel.addEvent(event);
        needsEnrollEvent = false;
        sendAnalytics();
        analyticsModel.markEnrolled();
      }
    } else if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_START) {
      if (needsStartEvent) {
        analyticsModel.addEvent(event);
        needsStartEvent = false;
        sendAnalytics();
        lastAnalyticsTriggered = System.currentTimeMillis();
      }
      return;
    } else if (event.getEventType() == TiAnalyticsEventFactory.EVENT_APP_END) {
      needsStartEvent = true;
      analyticsModel.addEvent(event);
      sendAnalytics();
    } else {
      analyticsModel.addEvent(event);
      long now = System.currentTimeMillis();
      if (now - lastAnalyticsTriggered >= STATS_WAIT) {
        sendAnalytics();
        lastAnalyticsTriggered = now;
      }
    }
  }
Esempio n. 2
0
  public void setRootActivity(TiRootActivity rootActivity) {
    // TODO consider weakRef
    this.rootActivity = rootActivity;
    this.windowHandler = rootActivity;

    // calculate the display density
    DisplayMetrics dm = new DisplayMetrics();
    rootActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    switch (dm.densityDpi) {
      case DisplayMetrics.DENSITY_HIGH:
        {
          density = "high";
          break;
        }
      case DisplayMetrics.DENSITY_MEDIUM:
        {
          density = "medium";
          break;
        }
      case DisplayMetrics.DENSITY_LOW:
        {
          density = "low";
          break;
        }
    }

    if (collectAnalytics()) {
      analyticsIntent = new Intent(this, TiAnalyticsService.class);
      analyticsModel = new TiAnalyticsModel(this);
      needsEnrollEvent = analyticsModel.needsEnrollEvent();

      if (needsEnrollEvent()) {
        String deployType = systemProperties.getString("ti.deploytype", "unknown");
        postAnalyticsEvent(TiAnalyticsEventFactory.createAppEnrollEvent(this, deployType));
      }

      if (needsStartEvent()) {
        String deployType = systemProperties.getString("ti.deploytype", "unknown");

        postAnalyticsEvent(TiAnalyticsEventFactory.createAppStartEvent(this, deployType));
      }

    } else {
      needsEnrollEvent = false;
      needsStartEvent = false;
      Log.i(LCAT, "Analytics have been disabled");
    }
  }