1/** * 2 * WiderFunnel - GWO Tracking and Goal script functions for A/B Tests 3 * Copyright 2011, Stephen Liu 4 * WiderFunnel Marketing Optimization 5 * Website: http://www.widerfunnel.com 6 * 7 * Requires widerfunnel.lib.js 8 * Date: 2011-10-06 9 **/ 10 11 12// Initialize globals 13var _gaq = _gaq || [], 14 _wf = _wf || {}; 15 16if (typeof _wf._lib_client === 'undefined') { 17 18 var __WF_DOMAIN = 'none', // when using 'none' 19 __WF_DOCKETTE = 'N3V001-FE1'; 20 21 _udn = __WF_DOMAIN; 22 23 // Keep in global 24 function utmx_section(){} 25 function utmx(){} 26 27 _wf._lib_client = '1.9.7_wf'; 28 _wf.runTest = true; 29 _wf.redirect = location.search.indexOf("wfvar=") === -1; 30 31 // Overriden by GWO: 32 _wf.redirectParam = 'TrainzSimulator12_viewctrl.php'; // or 'control.html'; 33 _wf.varName = 'ctrl'; 34 _wf.swapbox = {}; 35 36 _wf._ExperimentConfig = { 37 defaultGa : 'UA-4716797-1', 38 // wfga : '', 39 wfgwo : 'UA-26096748-2', 40 domain : __WF_DOMAIN, 41 allowLinker : true, // use boolean value 42 allowHash : '', // use boolean value 43 cookieKey : __WF_DOCKETTE, 44 dockette : __WF_DOCKETTE, 45 cvslot : 1, // use slot 0 to disable cv tracking 46 k : '0651778490', 47 vpPattern : "/" + __WF_DOCKETTE, 48 async : true // async tracking 49 } 50 51 // Experiment State Info 52 _wf._ExperimentInfo = { 53 isGWOLibLoaded : false, 54 isGALibLoaded : !(typeof _gat === 'undefined' || !_gat || !_gat._getTracker), 55 isGoalTracked : false, 56 isVariationTracked : false, 57 isLive : "", 58 isPreview : "", 59 combinationCookie : _wf.readCookie(_wf._ExperimentConfig.cookieKey) 60 }; 61 62 // callback(data) - called if experiment is active and before redirect. 63 _wf.runABTest = function(opts) { 64 opts = opts || {}; 65 opts = { 66 callback : opts.callback || null, 67 enablePreviewCookie : opts.enablePreviewCookie || true 68 }; 69 70 var isLive = _wf._ExperimentInfo.isLive = utmx("live"), 71 isPreview = _wf._ExperimentInfo.isPreview = utmx("preview"); 72 73 74 if (_wf.runTest && _wf.redirect) { 75 if (isLive || isPreview) { 76 if (isPreview && opts.enablePreviewCookie) 77 _wf.setExperimentCookie({value:_wf.varName}); 78 if (opts.callback) { 79 opts.callback(_wf.varName); 80 } 81 _wf.controlPageRedirect(_wf.redirectParam); 82 } else if (typeof _wf.varName === 'undefined' || _wf.varName !== 'ctrl') { 83 if (isPreview && opts.enablePreviewCookie) 84 _wf.setExperimentCookie({value:_wf.varName}); 85 if (opts.callback) { 86 opts.callback(_wf.varName); 87 } 88 _wf.controlPageRedirect(_wf.redirectParam); 89 } 90 } 91 }; 92 93 // Example {cvslot : 2} 94 _wf.trackCombination = function(options) { 95 options = options || {}; 96 options = { 97 ga : options.ga || true, // load ga library? 98 cvslot : options.cvslot || _wf._ExperimentConfig.cvslot // Use 0 to turn off cv tracking 99 }; 100 101 // GA Tracking 102 var combo = _wf.readCookie(_wf._ExperimentConfig.cookieKey); 103 if (combo !== null) { 104 var vp = _wf._ExperimentConfig.vpPattern + "/combo/" + combo, 105 cv = {slot:options.cvslot, label:_wf._ExperimentConfig.dockette, value:combo, scope:1}; 106 107 if (_wf._ExperimentConfig.defaultGa) { 108 _wf.trackPageView({ 109 id:_wf._ExperimentConfig.defaultGa, 110 domain : _wf._ExperimentConfig.domain, 111 customVar: cv, 112 vp: vp, 113 referrerOverride:_wf.refOverride, 114 allowLinker : _wf._ExperimentConfig.allowLinker, 115 allowHash : _wf._ExperimentConfig.allowHash 116 }); 117 } 118 119 } 120 121 // GWO Tracking 122 _wf.trackPageView({ 123 name:'wfgwo', 124 id:_wf._ExperimentConfig.wfgwo, 125 domain : _wf._ExperimentConfig.domain, 126 vp: '/' + _wf._ExperimentConfig.k + '/test', 127 allowLinker : _wf._ExperimentConfig.allowLinker, 128 allowHash : _wf._ExperimentConfig.allowHash 129 }); 130 131 _wf._ExperimentInfo.isVariationTracked = true; 132 133 // Load GA library
134 _wf.loadGALib(); 135 }; 136 137 138 // Example {vp: 'vp/goal/'} override vp goal 139 _wf.trackGoal= function(options) { 140 options = options || {}; 141 options = { 142 vp : options.vp || "" 143 }; 144 145 // GA Tracking 146 var combo = _wf.readCookie(_wf._ExperimentConfig.cookieKey); 147 if (combo !== null) { 148 var vp = options.vp || _wf._ExperimentConfig.vpPattern + "/goal/" + combo; 149 150 if (_wf._ExperimentConfig.defaultGa) { 151 // vp: /dockette/goal/a 152 _wf.trackPageView({ 153 id:_wf._ExperimentConfig.defaultGa, 154 domain : _wf._ExperimentConfig.domain, 155 vp: vp, 156 allowLinker : _wf._ExperimentConfig.allowLinker, 157 allowHash : _wf._ExperimentConfig.allowHash 158 }); // Default tracker 159 } 160 161 if (_wf._ExperimentConfig.wfga) { 162 // vp: /dockette/goal/a 163 _wf.trackPageView({ 164 name:'wfga', 165 id:_wf._ExperimentConfig.wfga, 166 domain : _wf._ExperimentConfig.domain, 167 vp: vp, 168 allowLinker : _wf._ExperimentConfig.allowLinker, 169 allowHash : _wf._ExperimentConfig.allowHash 170 }); 171 } 172 } 173 174 // GWO Reporting 175 _wf.trackPageView({ name:'wfgwo', 176 id:_wf._ExperimentConfig.wfgwo, 177 domain : _wf._ExperimentConfig.domain, 178 vp: '/' + _wf._ExperimentConfig.k + '/goal', 179 allowLinker : _wf._ExperimentConfig.allowLinker, 180 allowHash : _wf._ExperimentConfig.allowHash}); 181 182 _wf._ExperimentInfo.isGoalTracked = true; 183 184 // Load GA library 185 _wf.loadGALib(); 186 }; 187 188 _wf.setExperimentCookie = function(options) { 189 options = options || {}; 190 options = { 191 key : options.key || _wf._ExperimentConfig.cookieKey, 192 value : options.value || _wf.varName, 193 days : options.days || 365, 194 domain : options.domain || "" 195 }; 196 197 if (options.domain) { 198 _wf.createCookie(options.key, options.value, options.days, options.domain); 199 } else { 200 _wf.createCookie(options.key, options.value, options.days); 201 } 202 }; 203 204 _wf.trackPageView = function(config) { 205 config = config || {}; 206 config = { 207 name :config.name || "", 208 id : config.id || "", 209 vp : config.vp || "", 210 domain : config.domain || "", 211 customVar : config.customVar || "", 212 allowLinker : config.allowLinker || "", 213 allowHash : config.allowHash || "", 214 referrerOverride : config.referrerOverride || "", 215 async: config.async || _wf._ExperimentConfig.async 216 }; 217 218 _wf.trackPageViewAsync(config); 219 }; 220 221 _wf.trackPageViewAsync = function(config) { 222 if (config.name) { 223 config.name = config.name + "." 224 } 225 _gaq.push([config.name + '_setAccount', config.id]); 226 227 if (config.domain) { 228 _gaq.push([config.name + '_setDomainName', config.domain]); 229 } 230 231 if (config.referrerOverride) { 232 _gaq.push([config.name + '_setReferrerOverride', config.referrerOverride]); 233 } 234 235 if (config.allowLinker) { 236 _gaq.push([config.name + '_setAllowLinker', config.allowLinker]); 237 } 238 239 if (config.allowHash) { 240 _gaq.push([config.name + '_setAllowHash', config.allowHash]); 241 } 242 243 if (config.customVar && config.customVar.slot != 0) { 244 var cv = config.customVar; 245 _gaq.push([config.name + '_setCustomVar', cv.slot, cv.label, cv.value, cv.scope]); 246 } 247 248 if (config.vp) {
249 _gaq.push([config.name + '_trackPageview', config.vp]); 250 } else { 251 _gaq.push([config.name + '_trackPageview']); 252 } 253 }; 254 255 // loads siteop.js library 256 _wf.loadGWOLib = function() { 257 if (!_wf._ExperimentInfo.isGWOLibLoaded) { 258 (function(){var k=_wf._ExperimentConfig.k,d=document,l=d.location,c=d.cookie;function f(n){ 259 if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash; 260 d.write('<sc'+'ript src="'+ 'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com' 261 +'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime=' 262 +new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+ 263 '" type="text/javascript" charset="utf-8"></sc'+'ript>')})(); 264 265 // utmx not available yet. 266 _wf._ExperimentInfo.isGWOLibLo
266aded = true; 267 } 268 }; 269 270 _wf.loadGALib = function() { 271 if (!_wf._ExperimentInfo.isGALibLoaded) { 272 (function(){var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src=("https:"==document.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})(); 273 274 _wf._ExperimentInfo.isGALibLoaded = true; 275 } 276 }; 277 278} // end _lib_client
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.