-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleAnalytics.php
More file actions
executable file
·23 lines (23 loc) · 1017 Bytes
/
GoogleAnalytics.php
File metadata and controls
executable file
·23 lines (23 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
/**
* GoogleAnalytics Nodule
*/
final class GoogleAnalytics
{
/**
* Begins tracking this page, that is, reporting to Google servers activity associated with a particular account.
* @param string $accountNumber This is a number given to you by Google that uniquely associates you with your account.
*/
static function Track($accountNumber)
{
// URL to download Google Analytics API JavaScripts. Note that there is a http and a https version.
$url = (isset($_SERVER['HTTPS'])?'https://ssl.':'http://www.') . 'google-analytics.com/ga.js';
// Add those scripts.
ClientScript::AddSource($url, false);
// The code to report this use of the page to Google servers.
ClientScript::RaceQueue(WebPage::That(), '_gat', "pageTracker = _gat._getTracker('$accountNumber');pageTracker._trackPageview();");
// Report back to Google servers every time tokens are changed too.
URL::SetTracker(new RaceClientEvent('pageTracker', 'pageTracker._trackPageview', URL::Tokens));
}
}
?>