Created
May 16, 2012 22:23
-
-
Save jakevsrobots/2714507 to your computer and use it in GitHub Desktop.
A few utilities for triggering google analytics events from within Unity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class GoogleAnalytics { | |
public static string gameIdentifier = "YourGameName"; | |
public static void TrackEvent(string eventName, string eventLabel="") { | |
string googleAnalyticsCall = "_gaq.push(['_trackEvent', '" + GoogleAnalytics.gameIdentifier + "', '" + eventName + "'"; | |
if(eventLabel != "") { | |
googleAnalyticsCall += ", '" + eventLabel + "'"; | |
} | |
googleAnalyticsCall += "])"; | |
Debug.Log("Google analytics call: `" + googleAnalyticsCall + "`"); | |
Application.ExternalEval(googleAnalyticsCall); | |
} | |
public static void TrackEventWithValue(string eventName, string eventLabel, int eventValue) { | |
string googleAnalyticsCall = "_gaq.push(['_trackEvent', '" + GoogleAnalytics.gameIdentifier + "', '" + eventName + "'" + ", '" + eventLabel + "', " + eventValue + "])"; | |
Debug.Log("Google analytics call: `" + googleAnalyticsCall + "`"); | |
Application.ExternalEval(googleAnalyticsCall); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment