Search Images Maps Play YouTube News Gmail Drive More »
Sign in

Creative build guides

Expanding build guide

Add a timer

A timer lets you measure the length of any action in a creative, for example, the amount of time a user plays a game. There isn't a component for adding a timer to a creative, so you must use the API.

To start a timer:

Call the method:

enabler.startTimer(timerId:String);

To stop a timer:

Call this method:

enabler.stopTimer(timerId:String);

  • timerId is your timer's name in Studio. You can rename this in the Studio Web UI or in DFA Trafficking to change what shows up in the final report.
  • To successfully stop the timer, the timerId used in stopTimer must match the ID used in startTimer

Try it!

  • Add two buttons to your creative, naming one myStartTimerBtn and the other myStopTimerBtn.
  • Make a timer named "My Timer" start when the user clicks the myStartTimerBtn object and stop when the user clicks the myStopTimerBtn object.

AS3 code snippet

var onStartTimerHandler:Function = function(event:MouseEvent):void {
    enabler.startTimer("My Timer");
}

var onStopTimerHandler:Function = function(event:MouseEvent):void {
    enabler.stopTimer("My Timer");
}

myStartTimerBtn.addEventListener(MouseEvent.CLICK, onStartTimerHandler);
myStopTimerBtn.addEventListener(MouseEvent.CLICK, onStopTimerHandler);

Test your work

Run the creative in Flash. When you click the start and stop timer buttons, the following traces should appear in the output panel :

Enabler: Start timer: My Timer
Enabler: Stop timer: My Timer