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
+13.4k Golang : Query string with space symbol %20 in between
+17.1k Golang : Multi threading or run two processes or more example
+12.4k Golang : Transform comma separated string to slice example
+5.4k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+7.2k Golang : Create zip/ePub file without compression(use Store algorithm)
+21.8k Golang : Convert seconds to minutes and remainder seconds
+8.6k Golang : Gaussian blur on image and camera video feed examples
+6.3k Golang : How to determine if request or crawl is from Google robots
+5.7k Golang : Extract unicode string from another unicode string example
+5.5k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+6.1k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+16.3k Golang : Delete files by extension