Swift Module: Lifecycle

Swift Module: Lifecycle

by jason_koo on ‎02-21-2017 08:08 AM - edited on ‎06-01-2017 10:31 AM by Community Manager (598 Views)
This guide shows how to install and use the Lifecycle module from the Tealium Swift library. The Lifecycle module adds tracking for app lifecycle events such as launch, wake, sleep, and crashes.
 
The following topics are covered:
 
Table of Contents Placeholder

Features

  • Automatic tracking of Launch, Wake and sleep events (for targets utilizing UIKit)
  • Internal lifecycle data persistence
  • Basic crash detection (no stack trace)

Requirements

  • Swift 3.0+
  • Foundation dependency
  • UIKit dependency for autotracked lifecycle events

Installation & Configuration

The Lifecycle module is now automatically included with the default framework build if using Carthage.  See Adding Tealium to your Swift App for more information.  If adding manually, include the 'tealium/lifecycle' folder and all its files to the target build.

If the UIKit dependency is added to the target app, no further configuration or implementation is necessary.  For other platform builds, the lifecycle functions can be triggered manually, see the Delegate Methods section below.

Methods

launchDetected

Update lifecycle records with a launch event and trigger a lifecycle event dispatch.

launchDetected()
// SAMPLE
func someMethodCalledAtLaunchTime {

// Presuming 'tealium' was initialized earlier
tealium.lifecycle().launchDetected()

}

sleepDetected

Update lifecycle records with a sleep event and trigger a lifecycle event dispatch.

sleepDetected()
// SAMPLE
func someMethodCalledBeforeAppTerminated {

// Presuming 'tealium' was initialized earlier
tealium.lifecycle().sleepDetected()

}

wakeDetected

Update lifecycle records with a wake event and trigger a lifecycle event dispatch.

wakeDetected() calls can be safely added after a launchDetected() in the same function. The module will only accept a single launch event per instantiated instance.  

wakeDetected()
// SAMPLE
func someMethodCalledWhenAppStarts {

// Presuming 'tealium' was initialized earlier
tealium.lifecycle().wakeDetected()

}

Data Layer Variables

The module adds the following additional variables:

Variable Description Type Example
lifecycle_diddetect_crash Was a crash detected during this launch/wake event.  Populated only if true. Boolen "true"
lifecycle_dayofweek_local Local day of week that call was made - 1=Sunday, 2=Monday, etc.) Number "13"
lifecycle_dayssincelaunch Days since first launch in integer increments Number "23"
lifecycle_dayssinceupdate Days since the last detected app version update in integer increments Number "46"
lifecycle_dayssincelastwake Days since last detected wake in integer increments Number "1"
lifecycle_firstlaunchdate GMT timestamp of very first detected launch/wake in ISO8601 format from Zulu time String "2013-07-11T17:55:04Z" 
lifecycle_firstlaunchdate_MMDDYYYY  GMT Timestamp formatted as MM/DD/YYYY  String "01/18/2012"
lifecycle_hourofday_local Local hour of day that call was made (24 hour format)  String "true"
lifecycle_isfirstlaunch Only present if call is very first launch/wake call String "true"
lifecycle_isfirstlaunchupdate  Only present if call is first launch/wake after a detected updated Boolean "true"
lifecycle_isfirstwakemonth Only present if call is first launch/wake of the month Boolean "true"
lifecycle_isfirstwaketoday Only present if call is first launch/wake of the day  Boolean  "true"
lifecycle_launchcount Total number of launches this version of your app (since the last update) Number "3"
lifecycle_priorsecondsawake  Whole seconds app was awake since last launch only. Aggregates total from all wakes prior. Sent only with lifecycle_type: launch calls.  Number  "126"
lifecycle_secondsawake Whole seconds app was awake since most recent wake/launch. Number "30"
lifecycle_sleepcount Total number of times your app has gone to sleep (resets if updated)  Number  "5" 
lifecycle_totalcrashcount Total number of crashes counted since install (only reset if app deleted)  Number  "21" 
lifecycle_totallaunchcount Total number of launches since install (only reset if app deleted)  Number  "3" 
lifecycle_totalsecondsawake  Total number of seconds your app has been in a woken/active state since app install (only reset if app deleted)  Number  "36"
lifecycle_totalsleepcount  Total number of times your app has gone into the background since app install (only reset if app deleted)   Number  "400"
lifecycle_totalwakecount  Total number of launches + wakes since install (only reset if app deleted)  Number   "563"
lifecycle_type   Type of lifecycle call String "launch", "wake", "sleep"
lifecycle_updatelaunchdate  GMT timestamp of first wake/launch after a version update has been detected  String  "2014-09-08T18:10:01Z"
lifecycle_wakecount  Total number of launches + wakes in this version of your app (resets if updated)  Number   "29"

Change Log

- Build 1 - Current