Created
October 18, 2019 01:28
-
-
Save ciccarone/80509836171dbee7db47d497c11c28e8 to your computer and use it in GitHub Desktop.
GTM UTM Link Click Data Variable
This file contains 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
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<!-- Google Tag Manager --> | |
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | |
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | |
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | |
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | |
})(window,document,'script','dataLayer','GTM-PM5JKZG');</script> | |
<!-- End Google Tag Manager --> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>GTM Testing</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="apple-touch-icon" href="apple-touch-icon.png"> | |
</head> | |
<body> | |
<a href="https://www.example.com/test?utm_campaign=reina-world">hello</a> | |
<script | |
src="https://code.jquery.com/jquery-3.4.1.min.js" | |
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" | |
crossorigin="anonymous"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('a').click(function(){ | |
var utm_campaign = getURLParameter($(this).attr('href'), 'utm_campaign'); | |
dataLayer.push({'utm_campaign': utm_campaign}); | |
}); | |
function getURLParameter(url, name) { | |
return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1]; | |
} | |
}); | |
</script> | |
<!-- Google Tag Manager (noscript) --> | |
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PM5JKZG" | |
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | |
<!-- End Google Tag Manager (noscript) --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment