Detect if Google Analytics and Developer Media are loaded properly or not
This is for my own future reference. I need a way to check if Digital Media and Google Analytics JavaScript objects are loaded properly. There are browser's extensions such as Ghostery and Disconnect that will interfere or surrogate JavaScript objects and nullify the analytics behind the ads.
Here you go!
<script type="text/javascript">
window.addEventListener('load', function()
{
if(typeof DMAds==='undefined')
{
console.log('Developer Media is not loaded');
}
else
{
console.log('Developer Media is loaded');
}
if(window._gaq && (typeof window._gaq.I!== 'undefined'))
{
console.log('Classic Google Analytics is loaded');
}
else
{
console.log('Classic Google Analytics is not loaded');
}
console.log(window._gaq.I.prefix);
}, false);
</script>
If the browser viewing the page with above JavaScript codes equips with Ghostery or Disconnect. You will see Developer Media is not loaded
and Classic Google Analytics is not loaded
under your browser's Console
tab.
References:
https://marthijnhoiting.com/detect-if-someone-is-blocking-google-analytics-or-google-tag-manager/
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8k Golang : Getting Echo framework StartAutoTLS to work
+6.1k Golang : Use NLP to get sentences for each paragraph example
+5k Which content-type(MIME type) to use for JSON data
+20k Golang : Append content to a file
+8.5k Golang : Check if integer is power of four example
+19.6k Golang : Display list of time zones with GMT
+8.5k Swift : Convert (cast) Character to Integer?
+12.3k Golang : Sort and reverse sort a slice of runes
+36.9k Golang : Display float in 2 decimal points and rounding up or down
+5.1k Google : Block or disable caching of your website content
+4.9k Unix/Linux : How to pipe/save output of a command to file?
+16.5k Golang :Trim white spaces from a string