Android 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 Android 7.3.0 SDK.

Required Dependencies

Analytics must be enabled to use this feature.

  • Verify analytics is enabled

    boolean analyticsEnabled = UAirship.shared().getAnalytics().isEnabled();
    
  • Enable analytics, if it isn’t already enabled

    UAirship.shared().getAnalytics().setEnabled(true);
    

Quickstart

AccountEventTemplate

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

AccountEventTemplate.newRegisteredTemplate().createEvent().track();

To create and track an account registered event with optional properties

AccountEventTemplate.newRegisteredTemplate()
                    .setValue(9.99)
                    .setCategory("premium")
                    .setTransactionId("12345")
                    .createEvent()
                    .track();

MediaEventTemplate

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

MediaEventTemplate.newConsumedTemplate().createEvent().track();

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

MediaEventTemplate.newConsumedTemplate(1.99).createEvent().track();

To create and track a consumed content event with optional properties

MediaEventTemplate.newConsumedTemplate(2.99)
                  .setCategory("entertainment")
                  .setId("12345")
                  .setDescription("Watching latest entertainment news.")
                  .setType("video")
                  .setAuthor("UA Enterprises")
                  .setFeature(true)
                  .setPublishedDate("August 25, 2016")
                  .createEvent()
                  .track();

To create and track a starred content event

MediaEventTemplate.newStarredTemplate().createEvent().track();

To create and track a starred content event with optional properties

MediaEventTemplate.newStarredTemplate()
                  .setCategory("entertainment")
                  .setId("12345")
                  .setDescription("Watching latest entertainment news.")
                  .setType("video")
                  .setAuthor("UA Enterprises")
                  .setFeature(true)
                  .setPublishedDate("August 25, 2016")
                  .createEvent()
                  .track();

To create and track a browsed content event

MediaEventTemplate.newBrowsedTemplate().createEvent().track();

To create and track a browsed content event with optional properties

MediaEventTemplate.newBrowsedTemplate()
                  .setCategory("entertainment")
                  .setId("12345")
                  .setType("video")
                  .setAuthor("UA Enterprises")
                  .setFeature(true)
                  .setPublishedDate("August 25, 2016")
                  .createEvent()
                  .track();

To create and track a shared content event

MediaEventTemplate.newSharedTemplate().createEvent().track();

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

MediaEventTemplate.newSharedTemplate("facebook", "social").createEvent().track();

To create and track a shared content event with optional properties

MediaEventTemplate.newSharedTemplate("facebook", "social")
                  .setCategory("entertainment")
                  .setId("12345")
                  .setDescription("Watching latest entertainment news.")
                  .setType("video")
                  .setAuthor("UA Enterprises")
                  .setFeature(true)
                  .setPublishedDate("August 24, 2016")
                  .createEvent()
                  .track();

RetailEventTemplate

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

RetailEventTemplate.newPurchasedTemplate().createEvent().track();

To create and track a purchased event with optional properties

RetailEventTemplate.newPurchasedTemplate()
                   .setCategory("mens shoes")
                   .setId("12345")
                   .setDescription("Low top")
                   .setValue(99.99)
                   .setTransactionId("13579")
                   .setBrand("SpecialBrand")
                   .setNewItem(true)
                   .createEvent()
                   .track();

To create and track a browsed event

RetailEventTemplate.newBrowsedTemplate().createEvent().track();

To create and track a browsed event with optional properties

RetailEventTemplate.newBrowsedTemplate()
                   .setCategory("mens shoes")
                   .setId("12345")
                   .setDescription("Low top")
                   .setValue(99.99)
                   .setTransactionId("13579")
                   .setBrand("SpecialBrand")
                   .setNewItem(true)
                   .createEvent()
                   .track();

To create and track an added-to-cart event

RetailEventTemplate.newAddedToCartTemplate().createEvent().track();

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

RetailEventTemplate.newAddedToCartTemplate()
                   .setCategory("mens shoes")
                   .setId("12345")
                   .setDescription("Low top")
                   .setValue(99.99)
                   .setTransactionId("13579")
                   .setBrand("SpecialBrand")
                   .setNewItem(true)
                   .createEvent()
                   .track();

To create and track a starred product event

RetailEventTemplate.newStarredProductTemplate().createEvent().track();

To create and track a starred product event with optional properties

RetailEventTemplate.newStarredProductTemplate()
                   .setCategory("mens shoes")
                   .setId("12345")
                   .setDescription("Low top")
                   .setValue(99.99)
                   .setTransactionId("13579")
                   .setBrand("SpecialBrand")
                   .setNewItem(true)
                   .createEvent()
                   .track();

To create and track a shared product event

RetailEventTemplate.newSharedProductTemplate().createEvent().track();

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

RetailEventTemplate.newSharedProductTemplate("facebook", "social").createEvent().track();

To create and track a shared product event with optional properties

RetailEventTemplate.newSharedProductTemplate("facebook", "social")
                   .setCategory("mens shoes")
                   .setId("12345")
                   .setDescription("Low top")
                   .setValue(99.99)
                   .setTransactionId("13579")
                   .setBrand("SpecialBrand")
                   .setNewItem(true)
                   .createEvent()
                   .track();