Skip to content

Instantly share code, notes, and snippets.

@jmertic
Created July 12, 2013 12:27
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jmertic/5984094 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
<!--
function setCookie(name, value, days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires;
}
var query = window.location.search.substr(1);
if (query.length > 0) {
var params = query.split("&");
for (var i=0; i<params.length; i++) {
var pos = params[i].indexOf("=");
var name = params[i].substring(0, pos);
if (name == "gclid") {
var value = params[i].substring(pos + 1);
setCookie(name, value, 90);
}
}
}
function readCookie(name) {
var n = name + "=";
var cookie = document.cookie.split(';');
for(var i=0;i < cookie.length;i++) {
var c = cookie[i];
while (c.charAt(0)==' '){c = c.substring(1,c.length);}
if (c.indexOf(n) == 0){return c.substring(n.length,c.length);}
}
return null;
}
window.onload = function() {
document.getElementById('AdWordsID ').value = readCookie('gclid');
}
-->
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment