Skip to content

Instantly share code, notes, and snippets.

@faizanayubi
Created November 14, 2017 11:39
Show Gist options
  • Save faizanayubi/62af764bb98271986e9602807e2f199e to your computer and use it in GitHub Desktop.
Save faizanayubi/62af764bb98271986e9602807e2f199e to your computer and use it in GitHub Desktop.
UTM Tracker vNative
<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');
if (campaign.length) {
jQuery('body').append(jQuery('<img>', {src: 'https://track.vnative.com/impPixel?adid=' + campaign + '&pid=' + source}));
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment