Last active
August 29, 2015 14:03
-
-
Save willrust/1f59eb7b4d067492226f to your computer and use it in GitHub Desktop.
KISSmetrics & Tapstream Android integration helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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