Created
February 12, 2011 18:46
-
-
Save joehoyle/823980 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var _gaq = nil; | |
var sharedGoogleAnalyticsAccount = nil; | |
@implementation GoogleAnalytics : CPObject | |
{ | |
CPString account @accessors; | |
int sentEvents; | |
} | |
- (id)init | |
{ | |
self = [super init]; | |
_gaq = _gaq || []; | |
sentEvents = 0; | |
return self; | |
} | |
+ (id)sharedAccount | |
{ | |
if( sharedGoogleAnalyticsAccount ) | |
return sharedGoogleAnalyticsAccount; | |
sharedGoogleAnalyticsAccount = [[self alloc] init]; | |
return sharedGoogleAnalyticsAccount; | |
} | |
- (void)setAccount:(CPString)anAccount | |
{ | |
account = anAccount; | |
_gaq.push(['_setAccount', account]); | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
} | |
- (void)trackEventForCategory:(CPString)aCategory action:(CPString)anAction | |
{ | |
sentEvents++; | |
_gaq.push( ["_trackEvent", aCategory, anAction] ); | |
} | |
- (void)trackEventForCategory:(CPString)aCategory action:(CPString)anAction label:(CPString)aLabel | |
{ | |
sentEvents++; | |
_gaq.push( ["_trackEvent", aCategory, anAction, aLabel] ); | |
} | |
- (void)trackEventForCategory:(CPString)aCategory action:(CPString)anAction label:(CPString)aLabel value:(int)aValue | |
{ | |
sentEvents++; | |
_gaq.push( ["_trackEvent", aCategory, anAction, aLabel, aValue] ); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment