iframe - How to detect if Google Analytics is loaded and able to track custom Events -


we're having issues when we're loading iframe video player sends playback events google universal analytics (analytics.js) loaded inside iframe (on domain). ga tracker not being loaded on ios devices , because of that, no event tracking being sent ga.

on android , other devices including desktop works fine, not on ios unless changed third-party cookies setting comes default on ios safari.

i did test using cookie-less method google analytics (https://github.com/foture/cookieless-google-analytics) , way ios devices able correctly send track events ga. however, want use method fallback when regular ga method don't work, because userid created via fingerprint method not unique on mobile devices.

so need way detect when regular ga method able track events , if not able, either because tracker not loaded or cookies disabled, use cookie-less method load ga , track events.

thanks!

you try using (seemingly) undocumented property on ga object: ga.loaded.

the reference property find in official documentation in example describing use of hitcallback e-commerce tracking:

// called when link product clicked. function onproductclick() {    // truncated google analytics example brevity.    // [...] }  <a href="/next-page.html" onclick="onproductclick(); return !ga.loaded;">android warhol t-shirt</a> 

you try similar to:

if (typeof ga !== 'undefined' && ga.hasownproperty('loaded') && ga.loaded === true) {    // ga loaded. custom events available    // ... } else {    // ga not loaded, fallback tracking implementation.    // ... } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -