Rich Media API handbook

Add DART macros to tracking pixels in Flash

Objective

You want to implement 1x1 tracking pixels that contain DoubleClick ad server macro data.

Solution

1x1 tracking pixels that contain DoubleClick ad server macro data must be coded in the FLA file of the Rich Media creative. The DoubleClick Studio API features methods that capture this DART macro data.

These are the methods that capture DoubleClick ad server macros:

enabler.getParameter("adv");
enabler.getParameter(“buy”);
enabler.getDartAdId();
enabler.getDartPageId();
enabler.getDartSiteId();
enabler.getDartRenderingId();
enabler.getDartCreativeId();
enabler.getDartSiteName();

How-to

Here's an example of a marketing pixel that captures DoubleClick ad server macro data:

http://somedomain.com/cgi-bin/query?adv.id=%eadv!&camp.id=%ebuy!&site.name=%s&site.id=%esid!&page.id=%epid!&ad.id=%eaid!&creative.id=%ecid!&render.id="%erid!&r=%n

You'll find the variables where DoubleClick ad server macros are defined in the URL string of the pixel. These variables have placeholders that you replace with the method in the Studio API.

This table shows which placeholder to replace with its corresponding method:

Macro
DoubleClick Studio API method
DoubleClick ad server parameter
%eadv! enabler.getParameter("adv"); advertiser ID
%eaid! enabler.getDartAdId(); ad ID
%ebuy! enabler.getParameter(“buy”); campaign ID
%ecid! enabler.getDartCreativeId(); creative ID
%epid! enabler.getDartPageId(); page ID
%erid! enabler.getDartRenderingId(); rendering ID
%esid! enabler.getDartSiteId(); site ID
%k No API available keyword value
%m No API available match code
%n No API available random number
%p No API available pattern match
%s enabler.getDartSiteName(); site name

Sample ActionScript code for AS3 users

     import com.google.ads.studio.HTMLEnabler;

     // get a reference to the HTMLEnabler;
     var enabler:HTMLEnabler = HTMLEnabler.getInstance();

     // Initialize the HTMLEnabler. The "this" keyword refers to the stage.
     enabler.init(this);

     //Gets the DoubleClick ad server ad id.
     enabler.getDartAdId(); 

In addition, the Flash IDE and DoubleClick Studio returns null and NaN values for each DoubleClick ad server macro when the pixel is loaded. The values can only be populated with the correct data when the creative is viewed from a live tag served on a web page. Furthermore, in order for the pixel to return the correct data, you must select the appropriate fields for each macro in the Data Passing section at the creative level in DFA/DCM.

The table above shows you the data that applies to each macro and Studio API method.

Sample ActionScript code for calling on the pixel

For ActionScript 3 users

import com.google.ads.studio.HtmlEnabler;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;

var enabler:HtmlEnabler = HtmlEnabler.getInstance();
enabler.init(this);


var loader:Loader = new Loader();

var _trackingPixelLoaded:Boolean;

var advid:String=enabler.getParameter('adv');
var cmpid:String=enabler.getParameter('buy');

var sname:String=enabler.getDartSiteName();
var sid:Number=enabler.getDartSiteId();
var pid:Number=enabler.getDartPageId();
var aid:Number=enabler.getDartAdId();
var cid:Number=enabler.getDartCreativeId();
var rid:Number=enabler.getDartRenderingId();

var rand:Number=Math.floor(Math.random()*10000000);

var url:String="http://somedomain.com/cgi-bin/query?adv.id="+advid+"&camp.id="+cmpid+"&site.name="+sname+"&site.id="+sid+"&page.id="+pid+"&ad.id="+aid+"&creative.id="+cid+"&render.id="+rid+"&r="+rand;

function loadTrackingPixel():void {
	if (!_trackingPixelLoaded) {
		
		trace("Loading pixel...");

		loader.load(new URLRequest(url));
		
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE,pixelLoaded);
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,pixelFailed);
		
		_trackingPixelLoaded=true;
	}
}

function pixelLoaded(e:Event):void{
	trace("Pixel loaded successfully.");
}

function pixelFailed(e:Event):void {
	trace("Pixel failed to load.");
}

loadTrackingPixel();

For ActionScript 2 users

var _trackingPixelLoaded:Boolean=false;

var advid:String=enabler.getParameter('adv');
var cmpid:String=enabler.getParameter('buy');

var sname:String=Enabler.getDartSiteName();
var sid:Number=Enabler.getDartSiteId();
var pid:Number=Enabler.getDartPageId();
var aid:Number=Enabler.getDartAdId();
var cid:Number=Enabler.getDartCreativeId();
var rid:Number=Enabler.getDartRenderingId();

var rand:Number=Math.floor(Math.random()*10000000);

var url:String="http://somedomain.com/cgi-bin/query?adv.id="+advid+"&camp.id=
"+cmpid+"&site.name="+sname+"&site.id="+sid+"&page.id=
"+pid+"&ad.id=
"+aid+"&creative.id="+cid+"&render.id="+rid+"&r="+rand;

function loadTrackingPixel():Void {

	if (!_trackingPixelLoaded) {

		trace("Loading pixel...");

		loadMovieNum(url,99);

		_trackingPixelLoaded=true;

	}

}

loadTrackingPixel();

For information on using DART macros in exits, see DoubleClick Studio macro exits.