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
+6.1k Golang : Accessing dataframe-go element by row, column and name example
+17.4k Golang : Set, Get and List environment variables
+7.6k Golang : Progress bar with ∎ character
+8.3k Golang : Web(Javascript) to server-side websocket example
+6.3k Golang : How to handle file size larger than available memory panic issue
+44.2k Golang : Read tab delimited file with encoding/csv package
+4.2k Golang : Constant and variable names in native language
+25.1k Golang : Encrypt and decrypt data with AES crypto
+10.7k Golang : How to detect a server/machine network interface capabilities?
+6k Linux : How to fix Brother HL-1110 printing blank page problem
+6.3k Golang : Scanf function weird error in Windows
+13.5k Golang : Normalize unicode strings for comparison purpose