Custom Events: Quick Start Guide

The purpose of this guide is to provide code samples that can be easily implemented to get started with Custom Events right away. While you can certainly build on this functionality over time, this implementation will yield value immediately and give you a pattern to use in the future.

The implementations below are intended to represent the highest impact Custom Event for a variety of business verticals, making it easy to pinpoint the best starting point for your app.

Some users will need to instrument Custom Events in a WebView, whereas this Quick Start Guide only addresses native code. For details on the process of setting up Custom Events in a WebView, and for more details on what Custom Events are and how they work, see Custom Events.

Beginning with 7.3.0 SDK, convenient templates are provided to create custom events for common account, media or retail related events. For more details, see the Android Event Templates and iOS Event Templates topic guides.

Retail

For a retail app, you may wish to track purchases in order to compare push activity with conversion decisions.

Add the following snippets to your checkout action - or confirmation page - to fire a Custom Event when a user buys something.

iOS Sample

// Create an event for purchased item with the item value
UACustomEvent *event = [UACustomEvent eventWithName:@"purchased" value:itemValue];

// Record the event
[[UAirship shared].analytics addEvent:event];

Android and Amazon Sample

// Create an event for purchased item with the item value
CustomEvent event = new CustomEvent.Builder("purchased")
        .setEventValue(itemValue)
        .create();

// Record the event
UAirship.shared().getAnalytics().addEvent(event);

Entertainment

For an entertainment app, try tracking video plays, to tell whether users are engaging with new content from push. The following code samples can be added to your video player to fire a Custom Event when a user starts watching a video in your app.

iOS Sample

// Create and name a simple event
UACustomEvent *event = [UACustomEvent eventWithName:@"consumed_content"];

// Record the event
[[UAirship shared].analytics addEvent:event];

Android and Amazon Sample

// Create and name a simple event
CustomEvent event = new CustomEvent.Builder("consumed_content").create();

// Record the event
UAirship.shared().getAnalytics().addEvent(event);

Gaming

For a gaming app, track bet placement activity to track the effect of push on conversion. The following code samples can be added to your bet placement confirmation button - or to your confirmation page - to fire a Custom Event when a user makes a bet.

iOS Sample

// Create a "placed_bet" event with the bet value
UACustomEvent *event = [UACustomEvent eventWithName:@"placed_bet" value:betValue];

// Record the event
[[UAirship shared].analytics addEvent:event];

Android and Amazon Sample

// Create a "placed_bet" event with the bet value
CustomEvent event = new CustomEvent.Builder("placed_bet")
        .setEventValue(betValue);

// Record the event
UAirship.shared().getAnalytics().addEvent(event);

News

For a news app, Urban Airship recommends tracking articles read, so that you can tell whether users are discovering more content from push. The following code samples can be added to your video player to fire a Custom Event when a user reads an article in your app.

iOS Sample

// Create the "consumed_content" event
UACustomEvent *event = [UACustomEvent eventWithName:@"consumed_content"];

// Record the event
[[UAirship shared].analytics addEvent:event];

Android and Amazon Sample

// Create the "consumed_content" event
CustomEvent event = new CustomEvent.Builder("consumed_content").create();

// Record the event it
UAirship.shared().getAnalytics().addEvent(event);