All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.segment.analytics.CountlyIntegration Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
package com.segment.analytics;

import android.app.Activity;
import android.content.Context;
import ly.count.android.api.Countly;

/**
 * Countly is a general-purpose analytics tool for your mobile apps, with reports like traffic
 * sources, demographics, event tracking and segmentation.
 *
 * @see Countly
 * @see Countly Integration
 * @see Countly Android SDK
 */
class CountlyIntegration extends AbstractIntegration {
  static final String COUNTLY_KEY = "Countly";
  Countly countly;

  @Override void initialize(Context context, JsonMap settings, boolean debuggingEnabled)
      throws IllegalStateException {
    countly = Countly.sharedInstance();
    countly.init(context, settings.getString("serverUrl"), settings.getString("appKey"));
  }

  @Override Countly getUnderlyingInstance() {
    return countly;
  }

  @Override String key() {
    return COUNTLY_KEY;
  }

  @Override void onActivityStarted(Activity activity) {
    super.onActivityStarted(activity);
    countly.onStart();
  }

  @Override void onActivityStopped(Activity activity) {
    super.onActivityStopped(activity);
    countly.onStop();
  }

  @Override void track(TrackPayload track) {
    super.track(track);
    event(track.event(), track.properties());
  }

  @Override void screen(ScreenPayload screen) {
    super.screen(screen);
    event(String.format(VIEWED_EVENT_FORMAT, screen.event()), screen.properties());
  }

  private void event(String name, Properties properties) {
    int count = properties.getInt("count", 1);
    double sum = properties.getDouble("sum", 0);
    countly.recordEvent(name, properties.toStringMap(), count, sum);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy