I'm encountering an issue with implementing Google Analytics. Despite extensive research, I haven't been able to find a resolution.
My objective is to include the user's email address as a custom variable in Google Analytics. I have integrated the Google Analytics snippet within a function and passed the user's email address accordingly.
Unfortunately, there seems to be no output from the GA plugin in the console window.
No JavaScript errors are showing up during my troubleshooting process.
Upon thorough examination of the code with breakpoints, the function executes completely, including entering the if statements.
While the ga.js file loads successfully, the __utm.gif file fails to be invoked.
<script type="text/javascript">
//<![CDATA[
function googleTrack(email) {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xyz']);
_gaq.push(['_trackPageview']);
if ((parent == null) || (!parent.IsCMSDesk)) {
//track user name
_gaq.push(['_setCustomVar',
1,
'email_address',
email,
3
]);
//if googleCustomVar is defined, it will track it. if not, won't
if (!((typeof (window.googleCustomVar) === "undefined") && (typeof (googleCustomVar) === "undefined"))) {
_gaq.push(['_setCustomVar',
2,
'section',
googleCustomVar,
3
]);
}
}
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
googleTrack('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dca8b9afa8b19cb4b9bdb0a8b4b9b8f2bfb3b1">[email protected]</a>');
</script>
Simplifying the code down to the basics results in successful execution:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xyz']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
What could be causing the issue here? The ultimate aim is to create a function that can track the user's email address as a customized variable in Google Analytics.