Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
google_analytics_snippet.h
1 
17 
19 #ifndef NET_INSTAWEB_REWRITER_GOOGLE_ANALYTICS_SNIPPET_H_
20 #define NET_INSTAWEB_REWRITER_GOOGLE_ANALYTICS_SNIPPET_H_
21 
22 namespace net_instaweb {
23 
24 const char kGaSnippetGetTracker[] = "_modpagespeed_getRewriteTracker(";
25 
26 const char kGaSnippetPrefix[] =
27  "var _gaq = _gaq || [];\n"
28  "(function(){\n"
29  " function functionName(fn) {\n"
30  " var name = /\\W*function\\s+([\\w\\$]+)\\(/.exec(fn);\n"
31  " if (!name)\n"
32  " return 'No name';\n"
33  " return name[1];\n"
34  " }\n"
35  " var nameSpace = '_gat';\n"
36  " var existingGat = window[nameSpace];\n"
37  " if (existingGat && typeof existingGat['_getTracker'] == 'function') {\n"
38  " return;\n"
39  " }\n"
40  "\n"
41  " var gaqAccounts = [];\n"
42  " function setAccount(acct, prefix) {\n"
43  " if (gaqAccounts[prefix] != acct) {\n"
44  " gaqAccounts[prefix] = acct;\n"
45  " _gaq.push([prefix + '_setAccount', acct]);\n"
46  " }\n"
47  " }\n"
48  "\n"
49  " window['_modpagespeed_getRewriteTracker'] = function(tracker_acct,\n"
50  " tracker_name) {\n"
51  " var prefix = tracker_name ? tracker_name + '.' : '';\n"
52  "\n"
53  " function deferTrackerFunc(fn) {\n"
54  " return function() {\n"
55  " setAccount(tracker_acct, prefix);\n"
56  " var pushArgs = [fn];\n"
57  " [].push.apply(pushArgs, arguments);\n"
58  " _gaq.push(pushArgs);\n"
59  " };\n"
60  " }\n"
61  " var pageTrackerMethodNames = [\n";
62 
63 const char kGaSnippetSuffix[] =
64  " ];\n"
65  " var pageTracker = {\n"
66  " _initData: function() {},\n"
67  " };\n"
68  " for (var i=pageTrackerMethodNames.length; i--;) {\n"
69  " var n = pageTrackerMethodNames[i];\n"
70  " pageTracker[n] = deferTrackerFunc(prefix + n);\n"
71  " }\n"
72  " return pageTracker;\n"
73  " };\n"
74  "\n"
75  " var ga = document.createElement('script');\n"
76  " ga.type = 'text/javascript'; ga.async = true;\n"
77  " ga.src = ('https:' == document.location.protocol ? 'https:///ssl' :\n"
78  " 'http:///www') + '.google-analytics.com/ga.js';\n"
79  " var s = document.getElementsByTagName('script')[0];\n"
80  " s.parentNode.insertBefore(ga, s);\n"
81  "})();\n";
82 }
83 
84 #endif