Skip to content

Instantly share code, notes, and snippets.

@markknol markknol/GATracker.hx Secret
Created Apr 21, 2014

Embed
What would you like to do?
package temple.net.tracking.analytics;
/**
* @author Thijs Broerse
*/
class GATracker
{
public static var debug:Bool;
static public function trackPageview(pageURL:String):Void
{
call(["_trackPageview", pageURL]);
}
static public function trackEvent(category:String, action:String, ?label:String, ?value:Float):Void
{
var args:Array<Dynamic> = ["_trackEvent", category, action];
if (label != null && label != "")
{
args.push(label);
if (!Math.isNaN(value)) args.push(value);
}
call(args);
}
static private function call(args:Array<Dynamic>):Void
{
#if flash
if (flash.external.ExternalInterface.available)
{
flash.external.ExternalInterface.call("_gaq.push", args);
}
else
{
if (debug) trace(args);
}
#elseif js
untyped _gaq.push(args);
#end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.