Skip to content

Instantly share code, notes, and snippets.

@jakevsrobots
Created May 16, 2012 22:23
Show Gist options
  • Save jakevsrobots/2714507 to your computer and use it in GitHub Desktop.
Save jakevsrobots/2714507 to your computer and use it in GitHub Desktop.
A few utilities for triggering google analytics events from within Unity.
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