Skip to content

Instantly share code, notes, and snippets.

@therajumandapati
Last active May 2, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therajumandapati/9c719cdb90b437983875995717a52b92 to your computer and use it in GitHub Desktop.
Save therajumandapati/9c719cdb90b437983875995717a52b92 to your computer and use it in GitHub Desktop.
GA Tracking before redirection
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX');
</script>
<script>
function redirect(url) {
gtag('event', 'your_event', {
'event_callback':
function () {
window.location.href = url;
}
});
}
</script>
<script type="text/javascript">
redirect("https://your-external-url.com");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment