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
+47.6k Golang : How to convert JSON string to map and slice
+10.8k Golang : Create S3 bucket with official aws-sdk-go package
+10.2k Golang : Generate random integer or float number
+13.6k Golang : How to check if a file is hidden?
+10.6k Golang : Get UDP client IP address and differentiate clients by port number
+31.2k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+10.4k Android Studio : Checkbox for user to select options example
+6.1k Golang : Extract sub-strings
+32k Golang : Copy directory - including sub-directories and files
+7.8k Golang : Append and add item in slice
+29k Golang : How to create new XML file ?
+8.5k Golang : Get final balance from bit coin address example