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.9k Golang : Force download file example
+16.7k Golang : Get command line arguments
+20.5k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+11.7k Python : Convert IPv6 address to decimal and back to IPv6
+29.9k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+14.7k Golang : Read a file line by line
+3.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+16.1k Golang : Multi threading or run two processes or more example
+5.2k Golang : Detect face in uploaded photo like GPlus
+19.2k Golang : Saving private and public key to files
+12.5k Golang : Compress and decompress file with compress/flate example
+32k Golang : Converting a negative number to positive number