Tracking events within an in-app message is achieved in a similar way events are tagged in other locations of your app. This documentation is located in our developer Javascript API docs for iOS and Android.
As an example, we can use a generic NPS survey template that we link to in a Project of ours located here. If you look at the code below, you see localytics.tagEvent("In-App Rating Result", attributes) ;.
This event is tied to the "submit" button via the function where this code is found. The tag event essentially names the submit button firing "In-App Rating Result" and displays the event under that title in the dashboard.
localytics.tagEvent("In-App Rating Result", attributes); // Set a custom dimension to an index not currently set // localytics.setCustomDimension(0, attributes["Rating"]);
What we see below are the attributes to the event localytics.tagEvent("In-App Rating Result", attributes) ;
. When the function formSubmit
is triggered, this code picks up the rating results and buckets them into "Promoter", "Neutral" or "Detractor" as values within the attribute "rating". There is also a second attribute called "raw rating".
function formSubmit() { var attributes = {}; if (ratingValue >= 9) { attributes["Rating"] = "Promoter"; } else if (ratingValue <= 6) { attributes["Rating"] = "Detractor"; } else { attributes["Rating"] = "Neutral"; } attributes["Raw Rating"] = ratingValue; attributes["Improve Option"] = $("#improve_option option:selected").text(); attributes["Details Text"] = $("#details_text").val(); attributes["Campaign"] = "cpp_12345678"; // needs to be changed to app campaign number if (localytics) { localytics.tagEvent("In-App Rating Result", attributes); // localytics.setCustomDimension(0, attributes["Rating"]); } }
For more information around in-app messaging such as custom clickthrough tracking and customizing the dismiss button, see our developer documentation for iOS and Android.