{"_id":"5a6b684793313c005b692e1e","category":{"_id":"5a6b684793313c005b692e0a","version":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-05T21:53:37.386Z","from_sync":false,"order":2,"slug":"reference","title":"Reference"},"parentDoc":null,"user":"55e5ba046015ce1900eadb8e","project":"57c87ef85754fa1700b1228d","version":{"_id":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":1,"createdAt":"2018-01-26T17:41:27.297Z","releaseDate":"2018-01-26T17:41:27.297Z","categories":["5a6b684793313c005b692e08","5a6b684793313c005b692e09","5a6b684793313c005b692e0a","5a6b684793313c005b692e0b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.5.3","version":"3.5.3"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-21T09:58:37.161Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":13,"body":"Events are an important part of monitoring the health of your app and providing your users with the best experience possible. Tracking key actions allows you to view funnels and gain important metrics.\n\n####Automatic Events\n\nOnce you initialize the SDK, Primer automatically tracks some key events for you, including but not limited to: install, app launch, session start, and the presentation of onboarding flows and screens.\n\n####Custom Events\n\nTo accompany our automatic events, we let you track your own custom ones, so you can make them part of your analytical process on the Dashboard. There are no limitations on what you track, and no setup is necessary for new event names or parameters, just pass in a string for the name and a JSONObject containing your parameters, and they all get associated with the event.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"String name = \\\"Time Travel Occurred\\\";\\nJSONObject jsonObject = new JSONObject();\\ntry {\\n    jsonObject.put(\\\"Date\\\", \\\"October 23, 2015\\\");\\n} catch (JSONException e) {\\n    e.printStackTrace();\\n}\\nPrimer.trackEventWithName(name, jsonObject);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n####Sending Events to Mixpanel\n\nIf you use Mixpanel for your event analysis, Primer can send the events used to track the success of your new onboarding directly in your Mixpanel account. For most Mixpanel setups, this is as easy as contacting your Primer service rep and providing the following information: Mixpanel Token, and Mixpanel Distinct ID.\n\nIf you are specifying another ID value, such as a Parse anonymous ID, then you'll need to send that value to Primer so we can use it when sending events t**o Mixpanel. To do so, attach a property to your Primer user called `mixpanel_distinct_id` with the value of that user's Mixpanel distinct ID, as soon as you have access to it, and you have initialized the Primer SDK:** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Map userPropMap = new HashMap();\\nuserPropMap.put(\\\"mixpanel_distinct_id\\\", MIXPANEL_ID);\\nPrimer.appendUserProperties(userPropMap);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n####Local Event Forwarding\n\nIn case you'd like to get notified about one of our automatic events being triggered we forward them through the `BroadcastReceiver` mechanism. All you have to do is register an receiver with action `PMREventAction` then receive PrimerEvent to get the event's type, name, and parameters (using getEventName(), getEventType() and getEventParameters() methods).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Register broadcast for listening local events\\nIntentFilter intentFilter = new IntentFilter(Primer.PMREventAction);\\nBroadcastReceiver broadcastReceiver = new BroadcastReceiver() {\\n\\t\\t:::at:::Override\\n  \\tpublic void onReceive(Context context, Intent intent) {\\n    \\t\\t// Handle the notification\\n  \\t\\t\\tPrimerEvent event = intent.getParcelableExtra(Primer.PMREvent);\\n  \\t}\\n};\\n\\nregisterReceiver(broadcastReceiver, intentFilter);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThese event types trigger a notification:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Event\",\n    \"h-1\": \"Type key\",\n    \"h-2\": \"Triggered\",\n    \"0-0\": \"Signup\",\n    \"1-0\": \"Login\",\n    \"2-0\": \"Logout\",\n    \"3-0\": \"Flow Started\",\n    \"4-0\": \"Flow Completed\",\n    \"5-0\": \"Screen Displayed\",\n    \"6-0\": \"Action Tapped\",\n    \"0-1\": \"PMRSignupEvent\",\n    \"1-1\": \"PMRLoginEvent\",\n    \"2-1\": \"PMRLogoutEvent\",\n    \"3-1\": \"PMRFlowStartedEvent\",\n    \"4-1\": \"PMRFlowCompletedEvent\",\n    \"5-1\": \"PMRScreenDisplayedEvent\",\n    \"6-1\": \"PMRActionTappedEvent\",\n    \"0-2\": \"When a user gets signed up.\",\n    \"1-2\": \"When a user gets logged in.\",\n    \"2-2\": \"When a user gets logged out.\",\n    \"3-2\": \"When a Primer Flow has started.\",\n    \"4-2\": \"When a Primer Flow has completed.\",\n    \"5-2\": \"When a Primer Flow's screen gets displayed.\",\n    \"6-2\": \"When an action is tapped on a Primer screen.\",\n    \"7-1\": \"PMRPermissionRequestedEvent\",\n    \"8-1\": \"PMRPermissionGrantedEvent\",\n    \"9-1\": \"PMRPermissionDeniedEvent\",\n    \"10-1\": \"PMRPermissionRestrictedEvent\",\n    \"11-1\": \"PMRPurchasedEvent\",\n    \"12-1\": \"PMRSubscribedEvent\",\n    \"13-1\": \"PMRInAppPurchaseCancelledEvent\",\n    \"14-1\": \"PMRInAppPurchaseRestrictedEvent\",\n    \"15-1\": \"PMRInAppPurchaseFailedEvent\",\n    \"15-2\": \"When an In-App Purchase fails.\",\n    \"14-2\": \"When a restriction blocks an In-App Purchase.\",\n    \"13-2\": \"When an In-App Purchase is cancelled.\",\n    \"12-2\": \"When an IAP subscription is purchased.\",\n    \"11-2\": \"When an IAP product is purchased.\",\n    \"10-2\": \"When a restriction blocks a permission request.\",\n    \"9-2\": \"When a permission gets denied.\",\n    \"8-2\": \"When a permission gets granted.\",\n    \"7-2\": \"When a permission is requested.\",\n    \"7-0\": \"Permission Requested\",\n    \"8-0\": \"Permission Granted\",\n    \"9-0\": \"Permission Denied\",\n    \"10-0\": \"Permission Restricted\",\n    \"11-0\": \"IAP Purchased\",\n    \"12-0\": \"IAP Subscribed\",\n    \"13-0\": \"IAP Cancelled\",\n    \"14-0\": \"IAP Restricted\",\n    \"15-0\": \"IAP Failed\"\n  },\n  \"cols\": 3,\n  \"rows\": 16\n}\n[/block]","excerpt":"","slug":"event-tracking","type":"basic","title":"Event Tracking"}
Events are an important part of monitoring the health of your app and providing your users with the best experience possible. Tracking key actions allows you to view funnels and gain important metrics. ####Automatic Events Once you initialize the SDK, Primer automatically tracks some key events for you, including but not limited to: install, app launch, session start, and the presentation of onboarding flows and screens. ####Custom Events To accompany our automatic events, we let you track your own custom ones, so you can make them part of your analytical process on the Dashboard. There are no limitations on what you track, and no setup is necessary for new event names or parameters, just pass in a string for the name and a JSONObject containing your parameters, and they all get associated with the event. [block:code] { "codes": [ { "code": "String name = \"Time Travel Occurred\";\nJSONObject jsonObject = new JSONObject();\ntry {\n jsonObject.put(\"Date\", \"October 23, 2015\");\n} catch (JSONException e) {\n e.printStackTrace();\n}\nPrimer.trackEventWithName(name, jsonObject);", "language": "java" } ] } [/block] ####Sending Events to Mixpanel If you use Mixpanel for your event analysis, Primer can send the events used to track the success of your new onboarding directly in your Mixpanel account. For most Mixpanel setups, this is as easy as contacting your Primer service rep and providing the following information: Mixpanel Token, and Mixpanel Distinct ID. If you are specifying another ID value, such as a Parse anonymous ID, then you'll need to send that value to Primer so we can use it when sending events t**o Mixpanel. To do so, attach a property to your Primer user called `mixpanel_distinct_id` with the value of that user's Mixpanel distinct ID, as soon as you have access to it, and you have initialized the Primer SDK:** [block:code] { "codes": [ { "code": "Map userPropMap = new HashMap();\nuserPropMap.put(\"mixpanel_distinct_id\", MIXPANEL_ID);\nPrimer.appendUserProperties(userPropMap);", "language": "java" } ] } [/block] ####Local Event Forwarding In case you'd like to get notified about one of our automatic events being triggered we forward them through the `BroadcastReceiver` mechanism. All you have to do is register an receiver with action `PMREventAction` then receive PrimerEvent to get the event's type, name, and parameters (using getEventName(), getEventType() and getEventParameters() methods). [block:code] { "codes": [ { "code": "// Register broadcast for listening local events\nIntentFilter intentFilter = new IntentFilter(Primer.PMREventAction);\nBroadcastReceiver broadcastReceiver = new BroadcastReceiver() {\n\t\t@Override\n \tpublic void onReceive(Context context, Intent intent) {\n \t\t// Handle the notification\n \t\t\tPrimerEvent event = intent.getParcelableExtra(Primer.PMREvent);\n \t}\n};\n\nregisterReceiver(broadcastReceiver, intentFilter);", "language": "java" } ] } [/block] These event types trigger a notification: [block:parameters] { "data": { "h-0": "Event", "h-1": "Type key", "h-2": "Triggered", "0-0": "Signup", "1-0": "Login", "2-0": "Logout", "3-0": "Flow Started", "4-0": "Flow Completed", "5-0": "Screen Displayed", "6-0": "Action Tapped", "0-1": "PMRSignupEvent", "1-1": "PMRLoginEvent", "2-1": "PMRLogoutEvent", "3-1": "PMRFlowStartedEvent", "4-1": "PMRFlowCompletedEvent", "5-1": "PMRScreenDisplayedEvent", "6-1": "PMRActionTappedEvent", "0-2": "When a user gets signed up.", "1-2": "When a user gets logged in.", "2-2": "When a user gets logged out.", "3-2": "When a Primer Flow has started.", "4-2": "When a Primer Flow has completed.", "5-2": "When a Primer Flow's screen gets displayed.", "6-2": "When an action is tapped on a Primer screen.", "7-1": "PMRPermissionRequestedEvent", "8-1": "PMRPermissionGrantedEvent", "9-1": "PMRPermissionDeniedEvent", "10-1": "PMRPermissionRestrictedEvent", "11-1": "PMRPurchasedEvent", "12-1": "PMRSubscribedEvent", "13-1": "PMRInAppPurchaseCancelledEvent", "14-1": "PMRInAppPurchaseRestrictedEvent", "15-1": "PMRInAppPurchaseFailedEvent", "15-2": "When an In-App Purchase fails.", "14-2": "When a restriction blocks an In-App Purchase.", "13-2": "When an In-App Purchase is cancelled.", "12-2": "When an IAP subscription is purchased.", "11-2": "When an IAP product is purchased.", "10-2": "When a restriction blocks a permission request.", "9-2": "When a permission gets denied.", "8-2": "When a permission gets granted.", "7-2": "When a permission is requested.", "7-0": "Permission Requested", "8-0": "Permission Granted", "9-0": "Permission Denied", "10-0": "Permission Restricted", "11-0": "IAP Purchased", "12-0": "IAP Subscribed", "13-0": "IAP Cancelled", "14-0": "IAP Restricted", "15-0": "IAP Failed" }, "cols": 3, "rows": 16 } [/block]