Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

Google Analytics Integration - Queue Never "Fired"

Open nickjacob opened this issue 9 years ago • 0 comments

Type of issue

Edge case / bug in Prebid GA Analytics Adapter

Description

Noticed a bug in a prebid implementation with GA analytics adapter where publisher had loaded GA through GTM, with analytics.js loading ~5-10s after prebid auction.

In this case, checkAnalytics() (which looks for window.ga and fires the events if it's present) is never fired after GA is actually loaded. This means that no events are sent to google analytics.

This may also show up dependent on other (blocking) content on the page--eg if a GA snippet is low in the page/after a blocking script, it may load too long after the prebid auction to allow for checkAnalytics() to be called when window.ga is present. So more pubs may have this issue intermittently leading to lost/incomplete data sent to GA.

Steps to reproduce

See fiddle here: http://jsfiddle.net/m99ttudx/1/

Line 61 adds a mock GA object. You can adjust the timeout to see it fire at low timeouts.

Expected results

GA should be fired regardless of when it's loaded. This could be done by polling for the new google analytics object:

var gaPoll = setTimeout(() => {
  checkAnalytics();
  if (!_enableCheck) {
    clearTimeout(gaPoll);
  }
}, GA_POLL_INTERVAL); // can be pretty long, maybe 1500ms?

Platform details

Observed in prebid v17, I think the relevant code in ga.js has been the same since it was added -- think around v11?

nickjacob avatar Jan 06 '17 17:01 nickjacob