middleman 2.0.9.pre.2 → 2.0.9.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/features/builder.feature +6 -0
- data/features/data.feature +16 -1
- data/features/fonts.feature +11 -0
- data/features/relative_assets.feature +8 -2
- data/features/step_definitions/middleman_steps.rb +9 -2
- data/fixtures/data-app/config.rb +3 -0
- data/fixtures/data-app/data/pages.yml +6 -0
- data/fixtures/data-app/source/index.html.haml +1 -0
- data/fixtures/data-app/source/layout.haml +3 -0
- data/fixtures/fonts-app/config.rb +0 -0
- data/fixtures/fonts-app/source/fonts/StMarie-Thin.otf +0 -0
- data/fixtures/fonts-app/source/stylesheets/fonts.css.sass +3 -0
- data/fixtures/glob-app/config.rb +1 -0
- data/fixtures/glob-app/source/index.html.haml +6 -0
- data/fixtures/glob-app/source/stylesheets/site.css.sass +1 -0
- data/fixtures/test-app/config.rb +1 -0
- data/fixtures/test-app/data/test2.json +4 -0
- data/fixtures/test-app/source/data3.html.erb +1 -0
- data/lib/middleman/base.rb +8 -3
- data/lib/middleman/builder.rb +61 -22
- data/lib/middleman/cli.rb +2 -1
- data/lib/middleman/core_extensions/assets.rb +1 -1
- data/lib/middleman/core_extensions/compass.rb +6 -2
- data/lib/middleman/core_extensions/data.rb +20 -3
- data/lib/middleman/templates/html5.rb +1 -0
- data/lib/middleman/templates/mobile.rb +17 -0
- data/lib/middleman/templates/mobile/source/404.html +38 -0
- data/lib/middleman/templates/mobile/source/README.markdown +64 -0
- data/lib/middleman/templates/mobile/source/crossdomain.xml +25 -0
- data/lib/middleman/templates/mobile/source/css/style.css +236 -0
- data/lib/middleman/templates/mobile/source/default.appcache +17 -0
- data/lib/middleman/templates/mobile/source/humans.txt +43 -0
- data/lib/middleman/templates/mobile/source/img/h/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/img/h/splash.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/apple-touch-icon-precomposed.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/splash.png +0 -0
- data/lib/middleman/templates/mobile/source/img/m/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/index.html +95 -0
- data/lib/middleman/templates/mobile/source/js/libs/jquery-1.5.1.js +8316 -0
- data/lib/middleman/templates/mobile/source/js/libs/jquery-1.5.1.min.js +16 -0
- data/lib/middleman/templates/mobile/source/js/libs/modernizr-custom.js +14 -0
- data/lib/middleman/templates/mobile/source/js/libs/respond.min.js +7 -0
- data/lib/middleman/templates/mobile/source/js/mylibs/helper.js +147 -0
- data/lib/middleman/templates/mobile/source/js/script.js +0 -0
- data/lib/middleman/templates/mobile/source/robots.txt +5 -0
- data/lib/middleman/templates/mobile/source/sitemap.xml +10 -0
- data/lib/middleman/templates/mobile/source/test/index.html +31 -0
- data/lib/middleman/templates/mobile/source/test/qunit/qunit.css +148 -0
- data/lib/middleman/templates/mobile/source/test/qunit/qunit.js +1265 -0
- data/lib/middleman/templates/mobile/source/test/tests.js +26 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/Readme.PDF +0 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx1.snippet +31 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx2.snippet +2 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/ga.aspx +195 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/sample.aspx +44 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/ga.jsp +225 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp1.snippet +35 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp2.snippet +2 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/sample.jsp +51 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/ga.php +176 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/php1.snippet +30 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/php2.snippet +4 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/sample.php +44 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/ga.pl +195 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/perl1.snippet +27 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/perl2.snippet +1 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/sample.pl +38 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/COPYING +202 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/bookmark_bubble.js +559 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.html +43 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.js +57 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/arrow.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/close.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/generate_base64_images +33 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/icon_calendar.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/README +27 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/databasefactory.js +45 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworker.js +324 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworker_test.html +393 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworkerstarter.js +32 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_gears.js +595 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_gears_test.html +404 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_html5.js +203 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_html5_test.html +468 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapperapi.js +202 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapperapi_test.html +51 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_resultset.js +71 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_resultset_test.html +86 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_transaction.js +196 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_transaction_test.html +221 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gearsutils.js +94 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gearsutils_test.html +84 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/global_functions.js +72 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/index.html +347 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/simplenotes.js +503 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/styles.css +66 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/template.js +75 -0
- data/lib/middleman/version.rb +1 -1
- data/middleman-x86-mingw32.gemspec +0 -1
- data/middleman.gemspec +3 -2
- metadata +116 -51
- data/lib/middleman/config.ru +0 -2
- data/lib/middleman/features/tiny_src.rb +0 -11
@@ -0,0 +1,35 @@
|
|
1
|
+
<%@ page import="java.io.UnsupportedEncodingException,
|
2
|
+
java.net.URLEncoder" %>
|
3
|
+
<%!
|
4
|
+
// Copyright 2009 Google Inc. All Rights Reserved.
|
5
|
+
private static final String GA_ACCOUNT = "ACCOUNT ID GOES HERE";
|
6
|
+
private static final String GA_PIXEL = "ga.jsp";
|
7
|
+
|
8
|
+
private String googleAnalyticsGetImageUrl(
|
9
|
+
HttpServletRequest request) throws UnsupportedEncodingException {
|
10
|
+
StringBuilder url = new StringBuilder();
|
11
|
+
url.append(GA_PIXEL + "?");
|
12
|
+
url.append("utmac=").append(GA_ACCOUNT);
|
13
|
+
url.append("&utmn=").append(Integer.toString((int) (Math.random() * 0x7fffffff)));
|
14
|
+
|
15
|
+
String referer = request.getHeader("referer");
|
16
|
+
String query = request.getQueryString();
|
17
|
+
String path = request.getRequestURI();
|
18
|
+
|
19
|
+
if (referer == null || "".equals(referer)) {
|
20
|
+
referer = "-";
|
21
|
+
}
|
22
|
+
url.append("&utmr=").append(URLEncoder.encode(referer, "UTF-8"));
|
23
|
+
|
24
|
+
if (path != null) {
|
25
|
+
if (query != null) {
|
26
|
+
path += "?" + query;
|
27
|
+
}
|
28
|
+
url.append("&utmp=").append(URLEncoder.encode(path, "UTF-8"));
|
29
|
+
}
|
30
|
+
|
31
|
+
url.append("&guid=ON");
|
32
|
+
|
33
|
+
return url.toString();
|
34
|
+
}
|
35
|
+
%>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
2
|
+
pageEncoding="ISO-8859-1"%>
|
3
|
+
<%@ page import="java.io.UnsupportedEncodingException,
|
4
|
+
java.net.URLEncoder" %>
|
5
|
+
<%!
|
6
|
+
private static final String GA_ACCOUNT = "MO-3845491-5";
|
7
|
+
private static final String GA_PIXEL = "ga.jsp";
|
8
|
+
|
9
|
+
private String googleAnalyticsGetImageUrl(
|
10
|
+
HttpServletRequest request) throws UnsupportedEncodingException {
|
11
|
+
StringBuilder url = new StringBuilder();
|
12
|
+
url.append(GA_PIXEL + "?");
|
13
|
+
url.append("utmac=").append(GA_ACCOUNT);
|
14
|
+
url.append("&utmn=").append(Integer.toString((int) (Math.random() * 0x7fffffff)));
|
15
|
+
|
16
|
+
String referer = request.getHeader("referer");
|
17
|
+
String query = request.getQueryString();
|
18
|
+
String path = request.getRequestURI();
|
19
|
+
|
20
|
+
if (referer == null || "".equals(referer)) {
|
21
|
+
referer = "-";
|
22
|
+
}
|
23
|
+
url.append("&utmr=").append(URLEncoder.encode(referer, "UTF-8"));
|
24
|
+
|
25
|
+
if (path != null) {
|
26
|
+
if (query != null) {
|
27
|
+
path += "?" + query;
|
28
|
+
}
|
29
|
+
url.append("&utmp=").append(URLEncoder.encode(path, "UTF-8"));
|
30
|
+
}
|
31
|
+
|
32
|
+
url.append("&guid=ON");
|
33
|
+
|
34
|
+
return url.toString();
|
35
|
+
}
|
36
|
+
%>
|
37
|
+
<html>
|
38
|
+
<head>
|
39
|
+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
40
|
+
<title>Sample Mobile Analytics Page</title>
|
41
|
+
</head>
|
42
|
+
<body>
|
43
|
+
|
44
|
+
Publishers content here.
|
45
|
+
<%
|
46
|
+
String googleAnalyticsImageUrl = googleAnalyticsGetImageUrl(request);
|
47
|
+
%>
|
48
|
+
<img src="<%= googleAnalyticsImageUrl %>" />
|
49
|
+
Testing: <%= googleAnalyticsImageUrl %>
|
50
|
+
</body>
|
51
|
+
</html>
|
@@ -0,0 +1,176 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
Copyright 2009 Google Inc. All Rights Reserved.
|
5
|
+
**/
|
6
|
+
|
7
|
+
// Tracker version.
|
8
|
+
define("VERSION", "4.4sh");
|
9
|
+
|
10
|
+
define("COOKIE_NAME", "__utmmobile");
|
11
|
+
|
12
|
+
// The path the cookie will be available to, edit this to use a different
|
13
|
+
// cookie path.
|
14
|
+
define("COOKIE_PATH", "/");
|
15
|
+
|
16
|
+
// Two years in seconds.
|
17
|
+
define("COOKIE_USER_PERSISTENCE", 63072000);
|
18
|
+
|
19
|
+
// 1x1 transparent GIF
|
20
|
+
$GIF_DATA = array(
|
21
|
+
chr(0x47), chr(0x49), chr(0x46), chr(0x38), chr(0x39), chr(0x61),
|
22
|
+
chr(0x01), chr(0x00), chr(0x01), chr(0x00), chr(0x80), chr(0xff),
|
23
|
+
chr(0x00), chr(0xff), chr(0xff), chr(0xff), chr(0x00), chr(0x00),
|
24
|
+
chr(0x00), chr(0x2c), chr(0x00), chr(0x00), chr(0x00), chr(0x00),
|
25
|
+
chr(0x01), chr(0x00), chr(0x01), chr(0x00), chr(0x00), chr(0x02),
|
26
|
+
chr(0x02), chr(0x44), chr(0x01), chr(0x00), chr(0x3b)
|
27
|
+
);
|
28
|
+
|
29
|
+
// The last octect of the IP address is removed to anonymize the user.
|
30
|
+
function getIP($remoteAddress) {
|
31
|
+
if (empty($remoteAddress)) {
|
32
|
+
return "";
|
33
|
+
}
|
34
|
+
|
35
|
+
// Capture the first three octects of the IP address and replace the forth
|
36
|
+
// with 0, e.g. 124.455.3.123 becomes 124.455.3.0
|
37
|
+
$regex = "/^([^.]+\.[^.]+\.[^.]+\.).*/";
|
38
|
+
if (preg_match($regex, $remoteAddress, $matches)) {
|
39
|
+
return $matches[1] . "0";
|
40
|
+
} else {
|
41
|
+
return "";
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
// Generate a visitor id for this hit.
|
46
|
+
// If there is a visitor id in the cookie, use that, otherwise
|
47
|
+
// use the guid if we have one, otherwise use a random number.
|
48
|
+
function getVisitorId($guid, $account, $userAgent, $cookie) {
|
49
|
+
|
50
|
+
// If there is a value in the cookie, don't change it.
|
51
|
+
if (!empty($cookie)) {
|
52
|
+
return $cookie;
|
53
|
+
}
|
54
|
+
|
55
|
+
$message = "";
|
56
|
+
if (!empty($guid)) {
|
57
|
+
// Create the visitor id using the guid.
|
58
|
+
$message = $guid . $account;
|
59
|
+
} else {
|
60
|
+
// otherwise this is a new user, create a new random id.
|
61
|
+
$message = $userAgent . uniqid(getRandomNumber(), true);
|
62
|
+
}
|
63
|
+
|
64
|
+
$md5String = md5($message);
|
65
|
+
|
66
|
+
return "0x" . substr($md5String, 0, 16);
|
67
|
+
}
|
68
|
+
|
69
|
+
// Get a random number string.
|
70
|
+
function getRandomNumber() {
|
71
|
+
return rand(0, 0x7fffffff);
|
72
|
+
}
|
73
|
+
|
74
|
+
// Writes the bytes of a 1x1 transparent gif into the response.
|
75
|
+
function writeGifData() {
|
76
|
+
global $GIF_DATA;
|
77
|
+
header("Content-Type: image/gif");
|
78
|
+
header("Cache-Control: " .
|
79
|
+
"private, no-cache, no-cache=Set-Cookie, proxy-revalidate");
|
80
|
+
header("Pragma: no-cache");
|
81
|
+
header("Expires: Wed, 17 Sep 1975 21:32:10 GMT");
|
82
|
+
echo join($GIF_DATA);
|
83
|
+
}
|
84
|
+
|
85
|
+
// Make a tracking request to Google Analytics from this server.
|
86
|
+
// Copies the headers from the original request to the new one.
|
87
|
+
// If request containg utmdebug parameter, exceptions encountered
|
88
|
+
// communicating with Google Analytics are thown.
|
89
|
+
function sendRequestToGoogleAnalytics($utmUrl) {
|
90
|
+
$options = array(
|
91
|
+
"http" => array(
|
92
|
+
"method" => "GET",
|
93
|
+
"user_agent" => $_SERVER["HTTP_USER_AGENT"],
|
94
|
+
"header" => ("Accepts-Language: " . $_SERVER["HTTP_ACCEPT_LANGUAGE"]))
|
95
|
+
);
|
96
|
+
if (!empty($_GET["utmdebug"])) {
|
97
|
+
$data = file_get_contents(
|
98
|
+
$utmUrl, false, stream_context_create($options));
|
99
|
+
} else {
|
100
|
+
$data = @file_get_contents(
|
101
|
+
$utmUrl, false, stream_context_create($options));
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
// Track a page view, updates all the cookies and campaign tracker,
|
106
|
+
// makes a server side request to Google Analytics and writes the transparent
|
107
|
+
// gif byte data to the response.
|
108
|
+
function trackPageView() {
|
109
|
+
$timeStamp = time();
|
110
|
+
$domainName = $_SERVER["SERVER_NAME"];
|
111
|
+
if (empty($domainName)) {
|
112
|
+
$domainName = "";
|
113
|
+
}
|
114
|
+
|
115
|
+
// Get the referrer from the utmr parameter, this is the referrer to the
|
116
|
+
// page that contains the tracking pixel, not the referrer for tracking
|
117
|
+
// pixel.
|
118
|
+
$documentReferer = $_GET["utmr"];
|
119
|
+
if (empty($documentReferer) && $documentReferer !== "0") {
|
120
|
+
$documentReferer = "-";
|
121
|
+
} else {
|
122
|
+
$documentReferer = urldecode($documentReferer);
|
123
|
+
}
|
124
|
+
$documentPath = $_GET["utmp"];
|
125
|
+
if (empty($documentPath)) {
|
126
|
+
$documentPath = "";
|
127
|
+
} else {
|
128
|
+
$documentPath = urldecode($documentPath);
|
129
|
+
}
|
130
|
+
|
131
|
+
$account = $_GET["utmac"];
|
132
|
+
$userAgent = $_SERVER["HTTP_USER_AGENT"];
|
133
|
+
if (empty($userAgent)) {
|
134
|
+
$userAgent = "";
|
135
|
+
}
|
136
|
+
|
137
|
+
// Try and get visitor cookie from the request.
|
138
|
+
$cookie = $_COOKIE[COOKIE_NAME];
|
139
|
+
|
140
|
+
$visitorId = getVisitorId(
|
141
|
+
$_SERVER["HTTP_X_DCMGUID"], $account, $userAgent, $cookie);
|
142
|
+
|
143
|
+
// Always try and add the cookie to the response.
|
144
|
+
setrawcookie(
|
145
|
+
COOKIE_NAME,
|
146
|
+
$visitorId,
|
147
|
+
$timeStamp + COOKIE_USER_PERSISTENCE,
|
148
|
+
COOKIE_PATH);
|
149
|
+
|
150
|
+
$utmGifLocation = "http://www.google-analytics.com/__utm.gif";
|
151
|
+
|
152
|
+
// Construct the gif hit url.
|
153
|
+
$utmUrl = $utmGifLocation . "?" .
|
154
|
+
"utmwv=" . VERSION .
|
155
|
+
"&utmn=" . getRandomNumber() .
|
156
|
+
"&utmhn=" . urlencode($domainName) .
|
157
|
+
"&utmr=" . urlencode($documentReferer) .
|
158
|
+
"&utmp=" . urlencode($documentPath) .
|
159
|
+
"&utmac=" . $account .
|
160
|
+
"&utmcc=__utma%3D999.999.999.999.999.1%3B" .
|
161
|
+
"&utmvid=" . $visitorId .
|
162
|
+
"&utmip=" . getIP($_SERVER["REMOTE_ADDR"]);
|
163
|
+
|
164
|
+
sendRequestToGoogleAnalytics($utmUrl);
|
165
|
+
|
166
|
+
// If the debug parameter is on, add a header to the response that contains
|
167
|
+
// the url that was used to contact Google Analytics.
|
168
|
+
if (!empty($_GET["utmdebug"])) {
|
169
|
+
header("X-GA-MOBILE-URL:" . $utmUrl);
|
170
|
+
}
|
171
|
+
// Finally write the gif data to the response.
|
172
|
+
writeGifData();
|
173
|
+
}
|
174
|
+
?><?php
|
175
|
+
trackPageView();
|
176
|
+
?>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<?php
|
2
|
+
// Copyright 2009 Google Inc. All Rights Reserved.
|
3
|
+
$GA_ACCOUNT = "ACCOUNT ID GOES HERE";
|
4
|
+
$GA_PIXEL = "ga.php";
|
5
|
+
|
6
|
+
function googleAnalyticsGetImageUrl() {
|
7
|
+
global $GA_ACCOUNT, $GA_PIXEL;
|
8
|
+
$url = "";
|
9
|
+
$url .= $GA_PIXEL . "?";
|
10
|
+
$url .= "utmac=" . $GA_ACCOUNT;
|
11
|
+
$url .= "&utmn=" . rand(0, 0x7fffffff);
|
12
|
+
|
13
|
+
$referer = $_SERVER["HTTP_REFERER"];
|
14
|
+
$query = $_SERVER["QUERY_STRING"];
|
15
|
+
$path = $_SERVER["REQUEST_URI"];
|
16
|
+
|
17
|
+
if (empty($referer)) {
|
18
|
+
$referer = "-";
|
19
|
+
}
|
20
|
+
$url .= "&utmr=" . urlencode($referer);
|
21
|
+
|
22
|
+
if (!empty($path)) {
|
23
|
+
$url .= "&utmp=" . urlencode($path);
|
24
|
+
}
|
25
|
+
|
26
|
+
$url .= "&guid=ON";
|
27
|
+
|
28
|
+
return $url;
|
29
|
+
}
|
30
|
+
?>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<?php
|
2
|
+
$GA_ACCOUNT = "MO-3845491-5";
|
3
|
+
$GA_PIXEL = "ga.php";
|
4
|
+
|
5
|
+
function googleAnalyticsGetImageUrl() {
|
6
|
+
global $GA_ACCOUNT, $GA_PIXEL;
|
7
|
+
$url = "";
|
8
|
+
$url .= $GA_PIXEL . "?";
|
9
|
+
$url .= "utmac=" . $GA_ACCOUNT;
|
10
|
+
$url .= "&utmn=" . rand(0, 0x7fffffff);
|
11
|
+
|
12
|
+
$referer = $_SERVER["HTTP_REFERER"];
|
13
|
+
$query = $_SERVER["QUERY_STRING"];
|
14
|
+
$path = $_SERVER["REQUEST_URI"];
|
15
|
+
|
16
|
+
if (empty($referer)) {
|
17
|
+
$referer = "-";
|
18
|
+
}
|
19
|
+
$url .= "&utmr=" . urlencode($referer);
|
20
|
+
|
21
|
+
if (!empty($path)) {
|
22
|
+
$url .= "&utmp=" . urlencode($path);
|
23
|
+
}
|
24
|
+
|
25
|
+
$url .= "&guid=ON";
|
26
|
+
|
27
|
+
return $url;
|
28
|
+
}
|
29
|
+
?>
|
30
|
+
<html>
|
31
|
+
<head>
|
32
|
+
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
33
|
+
<title>Sample Mobile Analytics Page</title>
|
34
|
+
</head>
|
35
|
+
<body>
|
36
|
+
|
37
|
+
Publishers content here.
|
38
|
+
<?php
|
39
|
+
$googleAnalyticsImageUrl = googleAnalyticsGetImageUrl();
|
40
|
+
?>
|
41
|
+
<img src="<?= $googleAnalyticsImageUrl ?>" />
|
42
|
+
Testing: <?= $googleAnalyticsImageUrl ?>
|
43
|
+
</body>
|
44
|
+
</html>
|
@@ -0,0 +1,195 @@
|
|
1
|
+
#!/usr/bin/perl -w
|
2
|
+
#
|
3
|
+
# Copyright 2009 Google Inc. All Rights Reserved.
|
4
|
+
|
5
|
+
use CGI;
|
6
|
+
use Digest::MD5 qw(md5_hex);
|
7
|
+
use LWP::UserAgent;
|
8
|
+
use URI::Escape;
|
9
|
+
use strict;
|
10
|
+
|
11
|
+
# Tracker version.
|
12
|
+
use constant VERSION => '4.4sp';
|
13
|
+
|
14
|
+
use constant COOKIE_NAME => '__utmmobile';
|
15
|
+
|
16
|
+
# The path the cookie will be available to, edit this to use a different
|
17
|
+
# cookie path.
|
18
|
+
use constant COOKIE_PATH => '/';
|
19
|
+
|
20
|
+
# Two years.
|
21
|
+
use constant COOKIE_USER_PERSISTENCE => '+2y';
|
22
|
+
|
23
|
+
# 1x1 transparent GIF
|
24
|
+
my @GIF_DATA = (
|
25
|
+
0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
|
26
|
+
0x01, 0x00, 0x01, 0x00, 0x80, 0xff,
|
27
|
+
0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
|
28
|
+
0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
|
29
|
+
0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
|
30
|
+
0x02, 0x44, 0x01, 0x00, 0x3b);
|
31
|
+
|
32
|
+
my $query = new CGI;
|
33
|
+
|
34
|
+
# The last octect of the IP address is removed to anonymize the user.
|
35
|
+
sub get_ip {
|
36
|
+
my ($remote_address) = @_;
|
37
|
+
if ($remote_address eq "") {
|
38
|
+
return "";
|
39
|
+
}
|
40
|
+
|
41
|
+
# Capture the first three octects of the IP address and replace the forth
|
42
|
+
# with 0, e.g. 124.455.3.123 becomes 124.455.3.0
|
43
|
+
if ($remote_address =~ /^((\d{1,3}\.){3})\d{1,3}$/) {
|
44
|
+
return $1 . "0";
|
45
|
+
} else {
|
46
|
+
return "";
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
# Generate a visitor id for this hit.
|
51
|
+
# If there is a visitor id in the cookie, use that, otherwise
|
52
|
+
# use the guid if we have one, otherwise use a random number.
|
53
|
+
sub get_visitor_id {
|
54
|
+
my ($guid, $account, $user_agent, $cookie) = @_;
|
55
|
+
|
56
|
+
# If there is a value in the cookie, don't change it.
|
57
|
+
if ($cookie ne "") {
|
58
|
+
return $cookie;
|
59
|
+
}
|
60
|
+
|
61
|
+
my $message = "";
|
62
|
+
if ($guid ne "") {
|
63
|
+
# Create the visitor id using the guid.
|
64
|
+
$message = $guid . $account;
|
65
|
+
} else {
|
66
|
+
# otherwise this is a new user, create a new random id.
|
67
|
+
$message = $user_agent . get_random_number();
|
68
|
+
}
|
69
|
+
|
70
|
+
my $md5_string = md5_hex($message);
|
71
|
+
|
72
|
+
return "0x" . substr($md5_string, 0, 16);
|
73
|
+
}
|
74
|
+
|
75
|
+
# Get a random number string.
|
76
|
+
sub get_random_number {
|
77
|
+
return int(rand(0x7fffffff));
|
78
|
+
}
|
79
|
+
|
80
|
+
# Writes the bytes of a 1x1 transparent gif into the response.
|
81
|
+
sub write_gif_data {
|
82
|
+
my ($cookie, $utm_url) = @_;
|
83
|
+
|
84
|
+
my @header_args = (
|
85
|
+
-type => 'image/gif',
|
86
|
+
-Cache_Control =>
|
87
|
+
'private, no-cache, no-cache=Set-Cookie, proxy-revalidate',
|
88
|
+
-Pragma => 'no-cache',
|
89
|
+
-cookie => $cookie,
|
90
|
+
-expires => '-1d');
|
91
|
+
|
92
|
+
# If the debug parameter is on, add a header to the response that contains
|
93
|
+
# the url that was used to contact Google Analytics.
|
94
|
+
if (defined($query->param('utmdebug'))) {
|
95
|
+
push(@header_args, -X_GA_MOBILE_URL => $utm_url);
|
96
|
+
}
|
97
|
+
print $query->header(@header_args);
|
98
|
+
print pack("C35", @GIF_DATA);
|
99
|
+
}
|
100
|
+
|
101
|
+
# Make a tracking request to Google Analytics from this server.
|
102
|
+
# Copies the headers from the original request to the new one.
|
103
|
+
# If request containg utmdebug parameter, exceptions encountered
|
104
|
+
# communicating with Google Analytics are thown.
|
105
|
+
sub send_request_to_google_analytics {
|
106
|
+
my ($utm_url) = @_;
|
107
|
+
my $ua = LWP::UserAgent->new;
|
108
|
+
|
109
|
+
if (exists($ENV{'HTTP_ACCEPT_LANGUAGE'})) {
|
110
|
+
$ua->default_header('Accepts-Language' => $ENV{'HTTP_ACCEPT_LANGUAGE'});
|
111
|
+
}
|
112
|
+
if (exists($ENV{'HTTP_USER_AGENT'})) {
|
113
|
+
$ua->agent($ENV{'HTTP_USER_AGENT'});
|
114
|
+
}
|
115
|
+
|
116
|
+
my $ga_output = $ua->get($utm_url);
|
117
|
+
|
118
|
+
if (defined($query->param('utmdebug')) && !$ga_output->is_success) {
|
119
|
+
print $ga_output->status_line;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
# Track a page view, updates all the cookies and campaign tracker,
|
124
|
+
# makes a server side request to Google Analytics and writes the transparent
|
125
|
+
# gif byte data to the response.
|
126
|
+
sub track_page_view {
|
127
|
+
my $domain_name = "";
|
128
|
+
if (exists($ENV{'SERVER_NAME'})) {
|
129
|
+
$domain_name = $ENV{'SERVER_NAME'};
|
130
|
+
}
|
131
|
+
|
132
|
+
# Get the referrer from the utmr parameter, this is the referrer to the
|
133
|
+
# page that contains the tracking pixel, not the referrer for tracking
|
134
|
+
# pixel.
|
135
|
+
my $document_referer = "-";
|
136
|
+
if (defined($query->param('utmr'))) {
|
137
|
+
$document_referer = uri_unescape($query->param('utmr'));
|
138
|
+
}
|
139
|
+
my $document_path = "";
|
140
|
+
if (defined($query->param('utmp'))) {
|
141
|
+
$document_path = uri_unescape($query->param('utmp'));
|
142
|
+
}
|
143
|
+
|
144
|
+
my $account = $query->param('utmac');
|
145
|
+
my $user_agent = "";
|
146
|
+
if (exists($ENV{'HTTP_USER_AGENT'})) {
|
147
|
+
$user_agent = $ENV{'HTTP_USER_AGENT'};
|
148
|
+
}
|
149
|
+
|
150
|
+
# Try and get visitor cookie from the request.
|
151
|
+
my $cookie = "";
|
152
|
+
if (defined($query->cookie(COOKIE_NAME))) {
|
153
|
+
$cookie = $query->cookie(COOKIE_NAME);
|
154
|
+
}
|
155
|
+
|
156
|
+
my $guid = "";
|
157
|
+
if (exists($ENV{'HTTP_X_DCMGUID'})) {
|
158
|
+
$guid = $ENV{'HTTP_X_DCMGUID'};
|
159
|
+
}
|
160
|
+
|
161
|
+
my $visitor_id = get_visitor_id($guid, $account, $user_agent, $cookie);
|
162
|
+
|
163
|
+
# Always try and add the cookie to the response.
|
164
|
+
my $new_cookie = $query->cookie(
|
165
|
+
-name => COOKIE_NAME,
|
166
|
+
-value => $visitor_id,
|
167
|
+
-path => COOKIE_PATH,
|
168
|
+
-expires => COOKIE_USER_PERSISTENCE);
|
169
|
+
|
170
|
+
my $utm_gif_location = "http://www.google-analytics.com/__utm.gif";
|
171
|
+
|
172
|
+
my $remote_address = "";
|
173
|
+
if (exists($ENV{'REMOTE_ADDR'})) {
|
174
|
+
$remote_address = $ENV{'REMOTE_ADDR'};
|
175
|
+
}
|
176
|
+
|
177
|
+
# Construct the gif hit url.
|
178
|
+
my $utm_url = $utm_gif_location . '?' .
|
179
|
+
'utmwv=' . VERSION .
|
180
|
+
'&utmn=' . get_random_number() .
|
181
|
+
'&utmhn=' . uri_escape($domain_name) .
|
182
|
+
'&utmr=' . uri_escape($document_referer) .
|
183
|
+
'&utmp=' . uri_escape($document_path) .
|
184
|
+
'&utmac=' . $account .
|
185
|
+
'&utmcc=__utma%3D999.999.999.999.999.1%3B' .
|
186
|
+
'&utmvid=' . $visitor_id .
|
187
|
+
'&utmip=' . get_ip($remote_address);
|
188
|
+
|
189
|
+
send_request_to_google_analytics($utm_url);
|
190
|
+
|
191
|
+
# Finally write the gif data to the response.
|
192
|
+
write_gif_data($new_cookie, $utm_url);
|
193
|
+
}
|
194
|
+
|
195
|
+
track_page_view();
|