Tuesday 15 July 2014

javascript - How to avoid google-analytics-loading delaying load event listener when offline -


I have an app that works both online and offline. I have included GA in the body with ASCIN. I have the main functions related to the window related to the load event listener when the system is not connected, so it is very easy to try to load the ga.js file it takes time. This prevents the load event from firing, so how can I avoid this situation? I can use the DOMContentLoaded but this would be the same thing as JS files are included in DOM content.

Var loaded GoogleAnalytics = 0 ; Var gaClone; Var _gaq = _gaq || []; _gaq.push (['_ setAccount', 'UA-123456789-1']); _gaq.push (['_ trackPageview']); _gaq.push (function () {Loaded GoogleAnalytics = 1; //console.log ('GAG Actual Execution!');}); (Function () {var ga = document.createElement ('script'); ga.type = 'text / Javascript '; ga.async = true; ga.src = (' https: '== document.location.protocol? 'Http: //ssl': 'http: // www') + '.google-analytics.com / ga.js'; Var s = document.getElementsByTagName ('script') [0]; S.parentNode.insertBefore (GA, S); GaClone = ga;}) (); SetTimeout (function () {//console.log('timeout fired '); if (loaded GoogleAnalytics! = 1) {gaClone.parentNode.removeChild (gaClone);}}, 30000); & Lt; / Script & gt;

No comments:

Post a Comment