Last active
August 27, 2017 18:12
-
-
Save pongo/6af1acc96839aee45f45d7a3e3b3aa6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var OpenStatParser={_params:{},_parsed:!1,_decode64:function(r){if("function"==typeof window.atob)return atob(r);var t,a,e,n,i,s,o,h,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",p=0,f=0,u="",c=[];if(!r)return r;r+="";do n=d.indexOf(r.charAt(p++)),i=d.indexOf(r.charAt(p++)),s=d.indexOf(r.charAt(p++)),o=d.indexOf(r.charAt(p++)),h=n<<18|i<<12|s<<6|o,t=h>>16&255,a=h>>8&255,e=255&h,64==s?c[f++]=String.fromCharCode(t):64==o?c[f++]=String.fromCharCode(t,a):c[f++]=String.fromCharCode(t,a,e);while(p<r.length);return u=c.join("")},_parse:function(){var r=window.location.search.substr(1),t=r.split("&");this._params={};for(var a=0;a<t.length;a++){var e=t[a].split("=");this._params[e[0]]=e[1]}this._parsed=!0},hasMarker:function(){return this._parsed||this._parse(),"undefined"!=typeof this._params._openstat},buildCampaignParams:function(){if(!this.hasMarker())return!1;var r=this._decode64(this._params._openstat),t=r.split(";");return{utmcampaign:t[1],utmsource:t[0],utmcontent:t[2]}}}; | |
| if (OpenStatParser.hasMarker()) { | |
| var campaignParams = OpenStatParser.buildCampaignParams(); | |
| if (campaignParams !== false) { | |
| ga('set', {'campaignName': campaignParams.utmcampaign, 'campaignSource': campaignParams.utmsource, 'campaignMedium': 'cpc', 'campaignContent': campaignParams.utmcontent}); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var OpenStatParser = { | |
| _params: {}, | |
| _parsed: false, | |
| _decode64: function(data) { | |
| if (typeof window['atob'] === 'function') { | |
| return atob(data); | |
| } | |
| var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
| var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, | |
| ac = 0, | |
| dec = "", | |
| tmp_arr = []; | |
| if (!data) { | |
| return data; | |
| } | |
| data += ''; | |
| do { | |
| h1 = b64.indexOf(data.charAt(i++)); | |
| h2 = b64.indexOf(data.charAt(i++)); | |
| h3 = b64.indexOf(data.charAt(i++)); | |
| h4 = b64.indexOf(data.charAt(i++)); | |
| bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; | |
| o1 = bits >> 16 & 0xff; | |
| o2 = bits >> 8 & 0xff; | |
| o3 = bits & 0xff; | |
| if (h3 == 64) { | |
| tmp_arr[ac++] = String.fromCharCode(o1); | |
| } else if (h4 == 64) { | |
| tmp_arr[ac++] = String.fromCharCode(o1, o2); | |
| } else { | |
| tmp_arr[ac++] = String.fromCharCode(o1, o2, o3); | |
| } | |
| } while (i < data.length); | |
| dec = tmp_arr.join(''); | |
| return dec; | |
| }, | |
| _parse: function() { | |
| var prmstr = window.location.search.substr(1); | |
| var prmarr = prmstr.split('&'); | |
| this._params = {}; | |
| for (var i = 0; i < prmarr.length; i++) { | |
| var tmparr = prmarr[i].split('='); | |
| this._params[tmparr[0]] = tmparr[1]; | |
| } | |
| this._parsed = true; | |
| }, | |
| hasMarker: function() { | |
| if (!this._parsed) { | |
| this._parse(); | |
| } | |
| return (typeof this._params['_openstat'] !== 'undefined') ? true : false; | |
| }, | |
| buildCampaignParams: function() { | |
| if (!this.hasMarker()) { | |
| return false; | |
| } | |
| var openstat = this._decode64(this._params['_openstat']); | |
| var statarr = openstat.split(';'); | |
| return { | |
| utmcampaign: statarr[1], | |
| utmsource: statarr[0], | |
| utmcontent: statarr[2] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment