Add Google Analytics in Twine Game
Here is Code,
You need to add in First page or Second page as you want. So, keep adding in those pages.
You need to edit in UA-XXXXXXXXX-X and replace your GA code.
Whether you are in Harlow or Sugar, it works. Credit to original creator.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '[UA-XXXXXXXXX-X]');
// End of google-specific code ^
// This is the custom Event Listener that will allow Twine
// to record your users' passage clicks
document.addEventListener('click', function (event) {
if (event.target.matches('tw-link')) {
console.log("A tw-link was clicked");
var linkText = event.target.textContent;
console.log("Link text is");
console.log(linkText);
gtag('event', 'Navigation', {
'event_label': linkText,
'event_category': 'LinkTextClicked',
});
}
}, false);
</script>
If you have trouble in adding it, let me know it in Comment box.
No comments:
Post a Comment