Skip to content

Commit

Permalink
mixpanel: set "batch" as "$source" (integration id)
Browse files Browse the repository at this point in the history
add utm_ prefix to all UTM properties
update tests to match
  • Loading branch information
abarisain committed Dec 22, 2020
1 parent 8a0b8a5 commit 9a38422
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class MixpanelDispatcher implements BatchEventDispatcher
/**
* Mixpanel UTM tag keys
*/
private static final String CAMPAIGN = "campaign";
private static final String SOURCE = "source";
private static final String MEDIUM = "medium";
private static final String CONTENT = "content";
private static final String CAMPAIGN = "utm_campaign";
private static final String SOURCE = "utm_source";
private static final String MEDIUM = "utm_medium";
private static final String CONTENT = "utm_content";
private static final String INTEGRATION_ID = "$source";

/**
* UTM tag keys
Expand All @@ -53,7 +54,7 @@ public class MixpanelDispatcher implements BatchEventDispatcher
private static final String MESSAGING_CLICK_NAME = "batch_in_app_click";
private static final String UNKNOWN_EVENT_NAME = "batch_unknown";

private MixpanelAPI mixpanelInstance = null;
MixpanelAPI mixpanelInstance = null;

MixpanelDispatcher()
{
Expand Down Expand Up @@ -93,6 +94,7 @@ public void dispatchEvent(@NonNull Batch.EventDispatcher.Type type,
} else if (type.isMessagingEvent()) {
mixpanelParams = getInAppParams(payload);
}
mixpanelParams.put(INTEGRATION_ID, "batch");

if (mixpanelInstance != null) {
mixpanelInstance.trackMap(getMixpanelEventName(type), mixpanelParams);
Expand All @@ -107,7 +109,6 @@ private static Map<String, Object> getInAppParams(Batch.EventDispatcher.Payload
{
Map<String, Object> mixpanelParams = new HashMap<>();
mixpanelParams.put(CAMPAIGN, payload.getTrackingId());
mixpanelParams.put(SOURCE, "batch");
mixpanelParams.put(MEDIUM, "in-app");
mixpanelParams.put(BATCH_TRACKING_ID, payload.getTrackingId());

Expand Down Expand Up @@ -135,7 +136,6 @@ private static Map<String, Object> getInAppParams(Batch.EventDispatcher.Payload
private static Map<String, Object> getNotificationParams(Batch.EventDispatcher.Payload payload)
{
Map<String, Object> mixpanelParams = new HashMap();
mixpanelParams.put(SOURCE, "batch");
mixpanelParams.put(MEDIUM, "push");

String deeplink = payload.getDeeplink();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setUp() {
mixpanel = PowerMockito.mock(MixpanelAPI.class);

mixpanelDispatcher = new MixpanelDispatcher();
mixpanelDispatcher.setMixpanelInstance(mixpanel);
mixpanelDispatcher.mixpanelInstance = mixpanel;
}

@Test
Expand All @@ -60,8 +60,8 @@ public void testNotificationNoData() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "push");
expected.put("source", "batch");
expected.put("utm_medium", "push");
expected.put("$source", "batch");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_DISPLAY, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_display"), Mockito.eq(expected));
Expand All @@ -75,10 +75,11 @@ public void testNotificationDeeplinkQueryVars() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "push-batch");
expected.put("source", "batchsdk");
expected.put("campaign", "yoloswag");
expected.put("content", "button1");
expected.put("$source", "batch");
expected.put("utm_medium", "push-batch");
expected.put("utm_source", "batchsdk");
expected.put("utm_campaign", "yoloswag");
expected.put("utm_content", "button1");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_DISPLAY, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_display"), mapEq(expected));
Expand All @@ -92,10 +93,11 @@ public void testNotificationDeeplinkQueryVarsEncode() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "push-batch");
expected.put("source", "[batchsdk]");
expected.put("campaign", "yoloswag");
expected.put("content", "button1");
expected.put("$source", "batch");
expected.put("utm_medium", "push-batch");
expected.put("utm_source", "[batchsdk]");
expected.put("utm_campaign", "yoloswag");
expected.put("utm_content", "button1");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_DISPLAY, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_display"), mapEq(expected));
Expand All @@ -109,10 +111,11 @@ public void testNotificationDeeplinkFragmentVars() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "pushbatch01");
expected.put("source", "batch-sdk");
expected.put("campaign", "154879548754");
expected.put("content", "notif001");
expected.put("$source", "batch");
expected.put("utm_medium", "pushbatch01");
expected.put("utm_source", "batch-sdk");
expected.put("utm_campaign", "154879548754");
expected.put("utm_content", "notif001");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_OPEN, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_open"), mapEq(expected));
Expand All @@ -126,10 +129,11 @@ public void testNotificationDeeplinkFragmentVarsEncode() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "pushbatch01");
expected.put("source", "[batch-sdk]");
expected.put("campaign", "154879548754");
expected.put("content", "notif001");
expected.put("$source", "batch");
expected.put("utm_medium", "pushbatch01");
expected.put("utm_source", "[batch-sdk]");
expected.put("utm_campaign", "154879548754");
expected.put("utm_content", "notif001");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_OPEN, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_open"), mapEq(expected));
Expand All @@ -148,9 +152,10 @@ public void testNotificationCustomPayload() {
customPayload);

Map<String, Object> expected = new HashMap();
expected.put("medium", "654987");
expected.put("source", "jesuisuntest");
expected.put("campaign", "heinhein");
expected.put("$source", "batch");
expected.put("utm_medium", "654987");
expected.put("utm_source", "jesuisuntest");
expected.put("utm_campaign", "heinhein");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_DISPLAY, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_display"), mapEq(expected));
Expand All @@ -166,10 +171,11 @@ public void testNotificationDeeplinkPriority() {
customPayload);

Map<String, Object> expected = new HashMap();
expected.put("medium", "654987");
expected.put("source", "batchsdk");
expected.put("campaign", "yoloswag");
expected.put("content", "notif001");
expected.put("$source", "batch");
expected.put("utm_medium", "654987");
expected.put("utm_source", "batchsdk");
expected.put("utm_campaign", "yoloswag");
expected.put("utm_content", "notif001");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_OPEN, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_open"), mapEq(expected));
Expand All @@ -183,9 +189,10 @@ public void testNotificationDeeplinkNonTrimmed() {
customPayload);

Map<String, Object> expected = new HashMap();
expected.put("medium", "push");
expected.put("source", "batchsdk");
expected.put("campaign", "yoloswag");
expected.put("$source", "batch");
expected.put("utm_medium", "push");
expected.put("utm_source", "batchsdk");
expected.put("utm_campaign", "yoloswag");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_OPEN, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_open"), mapEq(expected));
Expand All @@ -200,9 +207,9 @@ public void testNotificationDismissCampaign() {
customPayload);

Map<String, Object> expected = new HashMap();
expected.put("medium", "push");
expected.put("source", "batch");
expected.put("campaign", "yoloswag");
expected.put("utm_medium", "push");
expected.put("$source", "batch");
expected.put("utm_campaign", "yoloswag");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.NOTIFICATION_DISMISS, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_notification_dismiss"), mapEq(expected));
Expand All @@ -216,9 +223,9 @@ public void testInAppNoData() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", null);
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", null);
expected.put("batch_tracking_id", null);

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_SHOW, payload);
Expand All @@ -234,10 +241,10 @@ public void testInAppShowUppercaseQueryVars() {

Map<String, Object> expected = new HashMap();
expected.put("batch_tracking_id", null);
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", null);
expected.put("content", "jesuisuncontent");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", null);
expected.put("utm_content", "jesuisuncontent");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_SHOW, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_show"), mapEq(expected));
Expand All @@ -252,10 +259,10 @@ public void testInAppShowUppercaseFragmentVars() {

Map<String, Object> expected = new HashMap();
expected.put("batch_tracking_id", null);
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", null);
expected.put("content", "jesuisuncontent");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", null);
expected.put("utm_content", "jesuisuncontent");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_SHOW, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_show"), mapEq(expected));
Expand All @@ -269,9 +276,9 @@ public void testInAppTrackingId() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", "jesuisunid");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", "jesuisunid");
expected.put("batch_tracking_id", "jesuisunid");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_CLICK, payload);
Expand All @@ -286,11 +293,11 @@ public void testInAppDeeplinkContentQueryVars() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", "jesuisunid");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", "jesuisunid");
expected.put("batch_tracking_id", "jesuisunid");
expected.put("content", "jesuisuncontent");
expected.put("utm_content", "jesuisuncontent");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_CLOSE, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_close"), mapEq(expected));
Expand All @@ -304,11 +311,11 @@ public void testInAppDeeplinkFragmentQueryVars() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", "jesuisunid");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", "jesuisunid");
expected.put("batch_tracking_id", "jesuisunid");
expected.put("content", "jesuisuncontent00587");
expected.put("utm_content", "jesuisuncontent00587");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_SHOW, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_show"), mapEq(expected));
Expand All @@ -322,11 +329,11 @@ public void testInAppDeeplinkContentPriority() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", "jesuisunid");
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", "jesuisunid");
expected.put("batch_tracking_id", "jesuisunid");
expected.put("content", "jesuisuncontent002");
expected.put("utm_content", "jesuisuncontent002");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_AUTO_CLOSE, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_auto_close"), mapEq(expected));
Expand All @@ -340,11 +347,11 @@ public void testInAppDeeplinkContentNoId() {
new HashMap());

Map<String, Object> expected = new HashMap();
expected.put("medium", "in-app");
expected.put("source", "batch");
expected.put("campaign", null);
expected.put("utm_medium", "in-app");
expected.put("$source", "batch");
expected.put("utm_campaign", null);
expected.put("batch_tracking_id", null);
expected.put("content", "jesuisuncontent");
expected.put("utm_content", "jesuisuncontent");

mixpanelDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_CLICK, payload);
Mockito.verify(mixpanel).trackMap(Mockito.eq("batch_in_app_click"), mapEq(expected));
Expand Down

0 comments on commit 9a38422

Please sign in to comment.