Follow

Using the Apmetrix Timer Function

The Apmetrix Timer functions allows you to track how long it takes your users to complete various events within your app. There is no limitation on timer duration as these events can span as much time as necessary for the event to be completed.  For instance, if you want to know the time it took your user to complete their first In-App Purchase or how long it took them to complete a particular tutorial.  Tracking the time it takes for users to perform a first time purchase along with other behavioral correlated data, can be instrumental in understanding buying habits and provide insights on how to decrease the buy cycle time. 

As a convenience to you the SDK already tracks the duration between when your user's first run your app and when they make their first In-App Purchase.  This timer event is automatically triggered with your first call to the inApPurchase() API method.  

Note that you can use this timer API to track an unlimited number of other timed events and you can have multiple timers running at the same time.

Following are four simple to use functions you will need to implement to accurately track event times.  They are explained in further detail below.

StartTimer(timerName) 

The start timer function initiates a timer for the specified timer name.  This stores an entry into the timer system with a name and a start timestamp equal to when this function was called.  The timer name is important as it is the same name that will be used later to stop the timer and it will also be what will be logged on the server and used when you generate reports that include timer event data.

Note: if you call startTimer again with the same timer name, the system will update that timer using the current timer as the new start timestamp and the original start time for that timer will be discarded.

The following are examples of how you would call the StartTimer method for the Unity, Android and iOS platforms:

Unity:

apmetrixObj.startTimer(string timerName);

Android:

Apmetrix.startTimer(String timerName);

iOS:

[Apmetrix startTimer:@”TimerName”];

 

StopTimer(timerName)

As the name suggests, the stop timer function stops the particular timer specified by the timer name and logs the name and duration for that timer with the Apmetrix Server.  This timer is then deleted from the system.  A timer with the same name cannot be stopped after this without being started again..

Note: attempts to call StopTimer with a timer name that had not been used previously in a call to StartTimer will be ignored.

The following are examples of how you would call the StartTimer function for the Unity, Android and iOS platforms:

Unity:

apmetrixObj.stopTimer(string timerName);

Android:

Apmetrix.stopTimer(String timerName);

IOS:

[Apmetrix stopTimer:@”TimerName”];

 

AppDidEnterBackground()

The AppDidEnterBackground functions handles all required tasks that the SDK needs to perform when your application enters the background.  For Timer functions It is important that this method be called in the proper location within your application so that the duration for the timer events you have started are accurate and only include the time the user is actively engaged with your application.  In addition to providing the syntax to use for each platform, instructions are given on where to place this Timer API function in your code.

Unity:

Called for you in the Apmetrix.cs file in the Unity Callback function OnApplicationPause()

apmetrixObj.appDidEnterBackground ();

Android:

You will need to override your activities onStop() functions and call this Timer API method when onStop() is automatically called as your activity transitions from foreground to background.

Apmetrix.appDidEnterBackground();

IOS:

You need to call this Timer API method from your AppDelegate's applicationDidEnterBackground: function so it is called as your application transitions from foreground to background.

[Apmetrix appDidEnterBackground];

 

AppWillEnterForeground ()

The AppWillEnterForegroundfunction handles the required functions as your app enters the foreground

The AppWillEnterForeground functions handles all required tasks that the SDK needs to perform when your application re-enters the foreground.  For Timer functions It is important that this method be called in the proper location within your application so that the duration for the timer events you have started are accurate and only include the time the user is actively engaged with your application.  In addition to providing the syntax to use for each platform, instructions are given on where to place this Timer API function in your code.

Unity:

Called for you in the Apmetrix.cs file in the Unity Callback function OnApplicationPause()

apmetrixObj. appWillEnterForeground();

Android:

You will need to override your activities onStart() functions and call this Timer API method when onStart() is automatically called as your activity transitions from background to foreground.  A reference to the current activity needs to be passed with this function call so the SDK can distinguish between a change in configuration (e.g. the Home or Back button pressed) versus just re-orienting the Android device from portrait to landscape or vice versa.

Apmetrix.appWillEnterForeground(Activity activity);

IOS:

You need to call this Timer API method from your AppDelegate's applicationWillEnterForeground: function so it is called as your application transitions from background to foreground.

[Apmetrix AppWillEnterForeground];

 

Have more questions? Submit a request