Is there a way to access the variable document.googleAnalytics
, added by Google Tag Manager, for A/B testing on a Vue.js page? I attempted to initialize the variable in both the mounted
and created
methods of the component, but it returns as undefined
:
export default {
data() {
return {
myVar: null,
}
},
mounted() {
this.myVar = document.googleAnalytics; // undefined
}
}
I also tried using a watcher for myVar
, but it did not resolve the issue:
watch: {
myVar(val) {
this.myVar = val;
}
}
Is it possible to retrieve the value from the document if the Tag Manager script is loaded after Vue has already been loaded and rendered?