Skip to content

Instantly share code, notes, and snippets.

@mattcdavis1
Last active January 28, 2018 00:45
Show Gist options
  • Save mattcdavis1/ef3ce694974e1307fac91f30b44cdae7 to your computer and use it in GitHub Desktop.
Save mattcdavis1/ef3ce694974e1307fac91f30b44cdae7 to your computer and use it in GitHub Desktop.
Adwords Phone Replacement
<script type="text/javascript">
(function() {
var pageId = Date.now();
var trackedAdwords = false;
var tracker = {
track: function () {
if (trackedAdwords) {
return;
}
var isAdwords = window.localStorage.getItem('isAdwords');
if (isAdwords === 'true') {
trackedAdwords = true;
}
$.ajax({
type: "POST",
url: 'https://api.cocounselor.com/api/track/' + window.location.host + '/' + pageId,
data: {
url: window.location.href,
referer: document.referrer,
user_agent: navigator.userAgent,
page_id: pageId,
is_adwords: isAdwords,
},
});
}
}
document.addEventListener("DOMContentLoaded", function(event) {
if (location.search.match('gclid=')) {
window.localStorage.setItem('isAdwords', 'true');
}
if (window.localStorage.getItem('isAdwords') === 'true') {
var phoneNumbers = document.querySelectorAll('[data-adwords-phone]');
for (i = 0; i < phoneNumbers.length; i++) {
var node = phoneNumbers[i];
var phoneNumber = node.getAttribute('data-adwords-phone');
var telNumber = 'tel:' + phoneNumber.replace(/\(|\)|-/g, '');
$(node).text(phoneNumber);
$(node).attr('href', telNumber);
}
tracker.track();
}
});
tracker.track();
})()
</script>
<span data-adwords-phone="(800) 530-9705" class="line-1 g-call-track">(770) 217-4954</span>
<span data-adwords-phone="(800) 530-9705" itemprop="telephone" class="g-call-track">(770) 217-4954</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment