From: maxious
Date: Sun, 20 Mar 2011 03:51:10 +0000
Subject: Add Google Analytics for Mobile
X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=4ac896cc245e1b7cfe70213237527d43967f34f6
---
Add Google Analytics for Mobile
---
--- a/common-template.inc.php
+++ b/common-template.inc.php
@@ -1,4 +1,28 @@
' . $pageTitle . '';
+
if ($datepicker) echo '';
if (isDebugServer()) echo '
@@ -128,6 +153,10 @@
}
echo '';
+ if (!isDebug()) {
+ $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl();
+ echo '';
+ }
}
function timePlaceSettings($geolocate = false)
{
--- /dev/null
+++ b/ga.php
@@ -1,1 +1,187 @@
+ array(
+ "method" => "GET",
+ "user_agent" => $_SERVER["HTTP_USER_AGENT"],
+ "header" => ("Accepts-Language: " . $_SERVER["HTTP_ACCEPT_LANGUAGE"]))
+ );
+ if (!empty($_GET["utmdebug"])) {
+ $data = file_get_contents(
+ $utmUrl, false, stream_context_create($options));
+ } else {
+ $data = @file_get_contents(
+ $utmUrl, false, stream_context_create($options));
+ }
+ }
+
+ // Track a page view, updates all the cookies and campaign tracker,
+ // makes a server side request to Google Analytics and writes the transparent
+ // gif byte data to the response.
+ function trackPageView() {
+ $timeStamp = time();
+ $domainName = $_SERVER["SERVER_NAME"];
+ if (empty($domainName)) {
+ $domainName = "";
+ }
+
+ // Get the referrer from the utmr parameter, this is the referrer to the
+ // page that contains the tracking pixel, not the referrer for tracking
+ // pixel.
+ $documentReferer = $_GET["utmr"];
+ if (empty($documentReferer) && $documentReferer !== "0") {
+ $documentReferer = "-";
+ } else {
+ $documentReferer = urldecode($documentReferer);
+ }
+ $documentPath = $_GET["utmp"];
+ if (empty($documentPath)) {
+ $documentPath = "";
+ } else {
+ $documentPath = urldecode($documentPath);
+ }
+
+ $account = $_GET["utmac"];
+ $userAgent = $_SERVER["HTTP_USER_AGENT"];
+ if (empty($userAgent)) {
+ $userAgent = "";
+ }
+
+ // Try and get visitor cookie from the request.
+ $cookie = $_COOKIE[COOKIE_NAME];
+
+ $guidHeader = $_SERVER["HTTP_X_DCMGUID"];
+ if (empty($guidHeader)) {
+ $guidHeader = $_SERVER["HTTP_X_UP_SUBNO"];
+ }
+ if (empty($guidHeader)) {
+ $guidHeader = $_SERVER["HTTP_X_JPHONE_UID"];
+ }
+ if (empty($guidHeader)) {
+ $guidHeader = $_SERVER["HTTP_X_EM_UID"];
+ }
+
+ $visitorId = getVisitorId($guidHeader, $account, $userAgent, $cookie);
+
+ // Always try and add the cookie to the response.
+ setrawcookie(
+ COOKIE_NAME,
+ $visitorId,
+ $timeStamp + COOKIE_USER_PERSISTENCE,
+ COOKIE_PATH);
+
+ $utmGifLocation = "http://www.google-analytics.com/__utm.gif";
+
+ // Construct the gif hit url.
+ $utmUrl = $utmGifLocation . "?" .
+ "utmwv=" . VERSION .
+ "&utmn=" . getRandomNumber() .
+ "&utmhn=" . urlencode($domainName) .
+ "&utmr=" . urlencode($documentReferer) .
+ "&utmp=" . urlencode($documentPath) .
+ "&utmac=" . $account .
+ "&utmcc=__utma%3D999.999.999.999.999.1%3B" .
+ "&utmvid=" . $visitorId .
+ "&utmip=" . getIP($_SERVER["REMOTE_ADDR"]);
+
+ sendRequestToGoogleAnalytics($utmUrl);
+
+ // If the debug parameter is on, add a header to the response that contains
+ // the url that was used to contact Google Analytics.
+ if (!empty($_GET["utmdebug"])) {
+ header("X-GA-MOBILE-URL:" . $utmUrl);
+ }
+ // Finally write the gif data to the response.
+ writeGifData();
+ }
+?>
+
--- a/index.php
+++ b/index.php
@@ -20,7 +20,7 @@
Timetables - Routes
Routes By Final Destination
Routes By Number
- Stops By Suburb
+ Routes By Suburb
Nearby Routes
';
-echo ' Other Trips: ';
+echo '
Via:
' . implode(", ", $viaPoints) . '
';
+echo 'Other Trips:
';
foreach ($routetrips as $othertrip) {
echo '' . midnight_seconds_to_time($othertrip[0]) . ' ';
}
-echo ' Other directions/timing periods: ';
+echo 'Other directions/timing periods:
';
$url = $APIurl . "/json/routesearch?routeshortname=" . $trips[1]->route_short_name;
$json = json_decode(getPage($url));
foreach ($json as $row) {