Mobile SDK end-of-life has been announced and scheduled for the end of 2023, in favor of updated and more streamlined app personalization using server-side APIs.
Dynamic yield provides an array of pre-defined events for tracking meaningful user interactions, such as purchase, login and add to cart. However, for unique interactions, or to send data from third parties, you can use custom events.
Custom events can have any name and send any data you want to Dynamic Yield. Common use cases include using events to trigger an experience, and sending information about a user’s attributes or behavior via an event to build audiences.
Custom event syntax
Use the following syntax to send data about interactions that are unique for your site.
Objective C syntax (iOS)
//Populating the Prop parameter
NSMutableDictionary* eventDictionary = [NSMutableDictionary dictionary];
[eventDictionary setObject:@"value1" forKey:@"key1"]; //add as many properties as you want, or no properties at all. Values can be in string or number format
[eventDictionary setObject:@"value2" forKey:@"key2"];
[eventDictionary setObject:@"value3" forKey:@"key3"];
//Sending the Event
[[DYApi getInstance] trackEvent:@"event name" prop:eventDictionary];
Swift syntax (iOS)
//Populating the Prop parameter
var props = Dictionary<String, String>();
props["key1"] = "value1"
props["key2"] = "value2"
props["key3"] = "value3"
//Sending the Event
DYApi.getInstance().trackEvent("event name", prop: props)
Java syntax (Android)
//Populating the Prop parameter
JSONObject props = new JSONObject();
props.put( "key1", "value1" );
props.put( "key2", "value2" );
props.put( "key3", "value3" );
//Sending the Event
DYApi.getInstance().trackEvent("event name", props );
Examples of common custom events
Example 1
Use an event to return the results of a survey, and trigger different experiences depending on the answers:
Objective C example (iOS):
//Populating the Prop parameter
NSMutableDictionary* eventDictionary = [NSMutableDictionary dictionary];
[eventDictionary setObject:@"8" forKey:@”shipping_speed_from_1_to_10”];
[eventDictionary setObject:@"9" forKey:@”quality_of_service_from_1_to_10”];
//Sending the Event
[[DYApi getInstance] trackEvent:@"'survey_data'" prop:eventDictionary];
Swift example (iOS):
//Populating the Prop parameter
var props = Dictionary<String, String>();
props["shipping_speed_from_1_to_10"] = "8"
props["quality_of_service_from_1_to_10"] = "9"
//Sending the Event
DYApi.getInstance().trackEvent("'survey_data'", prop: props)
Java example (Android):
//Populating the Prop parameter
JSONObject props = new JSONObject();
props.put( "shipping_speed_from_1_to_10", "8" );
props.put( "quality_of_service_from_1_to_1", "9" );
//Sending the Event
DYApi.getInstance().trackEvent("'survey_data'", props );
Example 2
Use an event to report the user’s age, gender, or behavior. This data may be obtained from the dataLayer of the browser or from the user’s behavior (click, scroll, etc.)
Report user’s gender (Objective C):
//Populating the Prop parameter
NSMutableDictionary* eventDictionary = [NSMutableDictionary dictionary];
[eventDictionary setObject:@"'female'" forKey:@”gender”];
//Sending the Event
[[DYApi getInstance] trackEvent:@"'user_gender'" prop:eventDictionary];
Report user’s gender (Swift):
//Populating the Prop parameter
var props = Dictionary<String, String>();
props["gender"] = "'female'"
//Sending the Event
DYApi.getInstance().trackEvent("'user_gender'", prop: props)
Report user’s gender (Java):
//Populating the Prop parameter
JSONObject props = new JSONObject();
props.put( "gender", "'female'" );
//Sending the Event
DYApi.getInstance().trackEvent("'user_gender'", props );
Report user’s age (Objective C):
//Populating the Prop parameter
NSMutableDictionary* eventDictionary = [NSMutableDictionary dictionary];
[eventDictionary setObject:@"29" forKey:@”age”];
//Sending the Event
[[DYApi getInstance] trackEvent:@”user_age” prop:eventDictionary];
Report user’s age (Swift):
//Populating the Prop parameter
var props = Dictionary<String, String>();
props["age"] = "29"
//Sending the Event
DYApi.getInstance().trackEvent(”user_age”, prop: props)
Report user’s age (Java):
//Populating the Prop parameter
JSONObject props = new JSONObject();
props.put( "age", "29" );
//Sending the Event
DYApi.getInstance().trackEvent(”user_age”, props );
Report user scrolled 70% of your page (Objective C):
//Sending the Event
[[DYApi getInstance] trackEvent:@”user_scrolled_70_percent_of_page” prop:NULL];
Report user scrolled 70% of your page (Swift):
//Sending the Event
DYApi.getInstance().trackEvent(”user_scrolled_70_percent_of_page”, prop: nil)
Report user scrolled 70% of your page (Java):
//Sending the Event
DYApi.getInstance().trackEvent(”user_scrolled_70_percent_of_page”, null );
Off-site events
You can also fire events from websites that have not installed the Dynamic Yield script (for example, 3rd party websites) using a pixel with the following syntax:
<img src="//px.dynamicyield.com/dpx?sec=1234567&name=TestEvent&props={" width="1" height="1" border="0">
Change TestEvent&props to your event name and property and change 1234567 to your Dynamic Yield section ID. If you are using the Dynamic Yield EU data center, replace px.dynamicyield.com with px-eu.dynamicyield.com.