Skip to content

Instantly share code, notes, and snippets.

@willrust
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willrust/1f59eb7b4d067492226f to your computer and use it in GitHub Desktop.
Save willrust/1f59eb7b4d067492226f to your computer and use it in GitHub Desktop.
KISSmetrics & Tapstream Android integration helper
#import org.json.JSONArray;
#import org.json.JSONException;
#import android.content.SharedPreferences;
SharedPreferences preferences = getApplicationContext().getSharedPreferences("MyKMPrefs", getApplicationContext().MODE_PRIVATE);
if (preferences.getBoolean("TSKMIdentified", false)) {return;}
Tapstream tracker = Tapstream.getInstance();
tracker.getConversionData(new ConversionListener() {
@Override
public void conversionData(String jsonData) {
if (jsonData != null) {
try {
JSONObject obj = new JSONObject(jsonData);
JSONArray hits = obj.getJSONArray("hits");
JSONObject hit = hits.getJSONObject(0);
JSONObject customParams = hit.getJSONObject("custom_parameters");
String kmId = customParams.getString("km_identity");
KISSmetricsAPI.sharedAPI().alias(kmId, KISSmetricsAPI.sharedAPI().identity());
// This should only need to be aliased once.
// KISSmetrics will retain the association between this alias and the user.
SharedPreferences preferences = getApplicationContext().getSharedPreferences("MyKMPrefs", getApplicationContext().MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("TSKMIdentified", true);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment