iOS Event Templates

Overview

The Urban Airship Event Templates provide a way to create custom events for common account, media or retail-related events. They are a wrapper for Custom Events and are available in UA iOS 7.3.0 SDK.

Resources

Required Dependencies

Analytics must be enabled to use this feature.

  • Verify analytics is enabled
let analyticsEnabled = UAirship.shared().analytics.isEnabled;
[BOOL analyticsEnabled = [UAirship shared].analytics.enabled;
  • Enable analytics, if it isn’t already enabled
UAirship.shared().analytics.isEnabled = true
[[UAirship shared].analytics.enabled = YES;

Quickstart

UAAccountEventTemplate

This template creates a custom event for account related events, such as a user registering for a paid premium account.

To create and track an account registered event

let acctTemplate = UAAccountEventTemplate.registeredTemplate()
let acctEvent = acctTemplate.createEvent()
acctEvent.track()
UAAccountEventTemplate *acctTemplate = [UAAccountEventTemplate registeredTemplate];
UACustomEvent *acctEvent = [acctTemplate createEvent];
[acctEvent track];

To create and track an account registered event with optional properties

let acctTemplate = UAAccountEventTemplate.registeredTemplate(withValue: 9.99)
acctTemplate.transactionID = "12345"
acctTemplate.category = "Premium"
let acctEvent = acctTemplate.createEvent()
acctEvent.track()
UAAccountEventTemplate *acctTemplate = [UAAccountEventTemplate registeredTemplateWithValue:@(9.99)];
acctTemplate.transactionID = @"12345";
acctTemplate.category = @"Premium";
UACustomEvent *acctEvent = [acctTemplate createEvent];
[acctEvent track];

UAMediaEventTemplate

This template creates a custom event for media-related events, such as a user playing a video, listening to an audio track, reading an article, sharing content, or starring content as their favorite.

To create and track a consumed content event

let mediaTemplate = UAMediaEventTemplate.consumed()
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate consumedTemplate];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a consumed content event with an optional value

let mediaTemplate = UAMediaEventTemplate.consumedTemplate(withValue: 1.99)
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate consumedTemplateWithValue:@(1.99)];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a consumed content event with optional properties

let mediaTemplate = UAMediaEventTemplate.consumedTemplate(withValue: 2.99)
mediaTemplate.category = "entertainment"
mediaTemplate.identifier = "12322"
mediaTemplate.eventDescription = "Watching latest entertainment news."
mediaTemplate.type = "video"
mediaTemplate.author = "UA Enterprises"
mediaTemplate.isFeature = true
mediaTemplate.publishedDate = "August 25, 2016"
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate consumedTemplateWithValue:@(2.99)];
mediaTemplate.category = @"entertainment";
mediaTemplate.identifier = @"12322";
mediaTemplate.eventDescription = @"Watching latest entertainment news.";
mediaTemplate.type = @"video";
mediaTemplate.author = @"UA Enterprises";
mediaTemplate.isFeature = YES;
mediaTemplate.publishedDate = @"August 25, 2016";
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a starred content event

let mediaTemplate = UAMediaEventTemplate.starred()
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate starredTemplate];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a starred content event with optional properties

let mediaTemplate = UAMediaEventTemplate.starred()
mediaTemplate.category = "entertainment"
mediaTemplate.identifier = "1234"
mediaTemplate.eventDescription = "Watching latest entertainment news."
mediaTemplate.type = "video"
mediaTemplate.author = "UA Enterprises"
mediaTemplate.isFeature = true
mediaTemplate.publishedDate = "August 25, 2016"
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate starredTemplate];
mediaTemplate.category = @"entertainment";
mediaTemplate.identifier = @"1234";
mediaTemplate.eventDescription = @"Watching latest entertainment news.";
mediaTemplate.type = @"video";
mediaTemplate.author = @"UA Enterprises";
mediaTemplate.isFeature = YES;
mediaTemplate.publishedDate = @"August 25, 2016";
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a browsed content event

let mediaTemplate = UAMediaEventTemplate.browsed()
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate browsedTemplate];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a browsed content event with optional properties

let mediaTemplate = UAMediaEventTemplate.browsed()
mediaTemplate.category = "entertainment"
mediaTemplate.identifier = "1234"
mediaTemplate.eventDescription = "Browsed latest entertainment news."
mediaTemplate.type = "video"
mediaTemplate.author = "UA Enterprises"
mediaTemplate.isFeature = true
mediaTemplate.publishedDate = "August 25, 2016"
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate browsedTemplate];
mediaTemplate.category = @"entertainment";
mediaTemplate.identifier = @"1234";
mediaTemplate.eventDescription = @"Browsed latest entertainment news.";
mediaTemplate.type = @"video";
mediaTemplate.author = @"UA Enterprises";
mediaTemplate.isFeature = YES;
mediaTemplate.publishedDate = @"August 25, 2016";
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a shared content event

let mediaTemplate = UAMediaEventTemplate.shared()
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate sharedTemplate];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a shared content event with optional Facebook source and social medium

let mediaTemplate = UAMediaEventTemplate.sharedTemplate(withSource: "facebook", withMedium: "social")
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate sharedTemplateWithSource:@"facebook" withMedium:@"social"];
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

To create and track a shared content event with optional properties

let mediaTemplate = UAMediaEventTemplate.sharedTemplate(withSource: "facebook", withMedium: "social")
mediaTemplate.category = "entertainment"
mediaTemplate.identifier = "1234"
mediaTemplate.eventDescription = "Watching latest entertainment news."
mediaTemplate.type = "video"
mediaTemplate.author = "UA Enterprises"
mediaTemplate.isFeature = true
mediaTemplate.publishedDate = "August 25, 2016"
let mediaEvent = mediaTemplate.createEvent()
mediaEvent.track()
UAMediaEventTemplate *mediaTemplate = [UAMediaEventTemplate sharedTemplateWithSource:@"facebook" withMedium:@"social"];
mediaTemplate.category = @"entertainment";
mediaTemplate.identifier = @"1234";
mediaTemplate.eventDescription = @"Watching latest entertainment news.";
mediaTemplate.type = @"video";
mediaTemplate.author = @"UA Enterprises";
mediaTemplate.isFeature = YES;
mediaTemplate.publishedDate = @"August 25, 2016";
UACustomEvent *mediaEvent = [mediaTemplate createEvent];
[mediaEvent track];

UARetailEventTemplate

This template creates a custom event for retail-related events, such as a user browsing a product, adding an item to a cart, purchasing an item, starring a product as their favorite or sharing a product.

To create and track a purchased event

let retailTemplate = UARetailEventTemplate.purchased()
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate purchasedTemplate];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a purchased event with optional properties

let retailTemplate = UARetailEventTemplate.purchasedTemplate(withValue: 99.99)
retailTemplate.category = "mens shoes"
retailTemplate.identifier = "12345"
retailTemplate.eventDescription = "Low top"
retailTemplate.transactionID = "13579"
retailTemplate.brand = "SpecialBrand"
retailTemplate.isNewItem = true
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate purchasedTemplateWithValue:@(99.99)];
retailTemplate.category = @"mens shoes";
retailTemplate.identifier = @"12345";
retailTemplate.eventDescription = @"Low top";
retailTemplate.transactionID = @"13579";
retailTemplate.brand = @"SpecialBrand";
retailTemplate.isNewItem = YES;
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a browsed event

let retailTemplate = UARetailEventTemplate.browsed()
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate browsedTemplate];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a browsed event with optional properties

let retailTemplate = UARetailEventTemplate.browsedTemplate(withValue: 99.99)
retailTemplate.category = "mens shoes"
retailTemplate.identifier = "12345"
retailTemplate.eventDescription = "Low top"
retailTemplate.transactionID = "13579"
retailTemplate.brand = "SpecialBrand"
retailTemplate.isNewItem = true
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate browsedTemplateWithValue:@(99.99)];
retailTemplate.category = @"mens shoes";
retailTemplate.identifier = @"12345";
retailTemplate.eventDescription = @"Low top";
retailTemplate.transactionID = @"13579";
retailTemplate.brand = @"SpecialBrand";
retailTemplate.isNewItem = YES;
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track an added-to-cart event

let retailTemplate = UARetailEventTemplate.addedToCart()
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate addedToCartTemplate];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track an added-to-cart event with optional properties

let retailTemplate = UARetailEventTemplate.addedToCartTemplate(withValue: 99.99)
retailTemplate.category = "mens shoes"
retailTemplate.identifier = "12345"
retailTemplate.eventDescription = "Low top"
retailTemplate.transactionID = "13579"
retailTemplate.brand = "SpecialBrand"
retailTemplate.isNewItem = true
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate addedToCartTemplateWithValue:@(99.99)];
retailTemplate.category = @"mens shoes";
retailTemplate.identifier = @"12345";
retailTemplate.eventDescription = @"Low top";
retailTemplate.transactionID = @"13579";
retailTemplate.brand = @"SpecialBrand";
retailTemplate.isNewItem = YES;
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a starred product event

let retailTemplate = UARetailEventTemplate.starredProduct()
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate starredProductTemplate];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a starred product event with optional properties

let retailTemplate = UARetailEventTemplate.starredProductTemplate(withValue: 99.99)
retailTemplate.category = "mens shoes"
retailTemplate.identifier = "12345"
retailTemplate.eventDescription = "Low top"
retailTemplate.transactionID = "13579"
retailTemplate.brand = "SpecialBrand"
retailTemplate.isNewItem = true
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate starredProductTemplateWithValue:@(99.99)];
retailTemplate.category = @"mens shoes";
retailTemplate.identifier = @"12345";
retailTemplate.eventDescription = @"Low top";
retailTemplate.transactionID = @"13579";
retailTemplate.brand = @"SpecialBrand";
retailTemplate.isNewItem = YES;
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a shared product event

let retailTemplate = UARetailEventTemplate.sharedProduct()
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate sharedProductTemplate];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a shared product event with optional Facebook source and social medium

let retailTemplate = UARetailEventTemplate.sharedProductTemplate(withSource: "facebook", withMedium: "social")
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate sharedProductTemplateWithSource:@"facebook" withMedium:@"social"];
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];

To create and track a shared product event with optional properties

let retailTemplate = UARetailEventTemplate.sharedProductTemplate(withSource: "facebook", withMedium: "social")
retailTemplate.category = "mens shoes"
retailTemplate.identifier = "12345"
retailTemplate.eventDescription = "Low top"
retailTemplate.transactionID = "13579"
retailTemplate.brand = "SpecialBrand"
retailTemplate.isNewItem = true
let retailEvent = retailTemplate.createEvent()
retailEvent.track()
UARetailEventTemplate *retailTemplate = [UARetailEventTemplate sharedProductTemplateWithSource:@"facebook" withMedium:@"social"];
retailTemplate.category = @"mens shoes";
retailTemplate.identifier = @"12345";
retailTemplate.eventDescription = @"Low top";
retailTemplate.transactionID = @"13579";
retailTemplate.brand = @"SpecialBrand";
retailTemplate.isNewItem = YES;
UACustomEvent *retailEvent = [retailTemplate createEvent];
[retailEvent track];