-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring ga tracker name when enabling ga analytics for Prebid #292
Conversation
Thanks for the PR @bborn |
Yeah, docs are here: https://developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers#getall
I'm pretty sure GTM also logs the timestamp to the dataLayer, but I didn't figure out exactly where/when. I don't think Prebid should do that though - there are cases where a uses might have set there own custom name, or where there are multiple trackers on the page (so how would Prebid know which one to use?). I think it makes more sense to just allow setting the name and then let the user pass it in (and maybe give an example of usage with GTM). |
if (typeof gaOptions.trackerName !== 'undefined') { | ||
_trackerName = gaOptions.trackerName; | ||
} else { | ||
_trackerName = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else isn't necessary, since it's already defined as null
@bborn |
@mkendall07 ok, does this look better? I'm a little out of my element here (JS/node), but I think setting a |
@@ -175,11 +182,16 @@ function getCpmDistribution(cpm) { | |||
return distribution; | |||
} | |||
|
|||
exports.prefixedSend = function(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be a function. Just do exports.prefixedSend = _trackerPrefix + 'send';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that exports.prefixedSend
need to be inside the enableAnalytics
function?
@mkendall07 updated to use |
Thanks, could you flatten these two commits? And then we'll be ready to merge. |
Done. |
@@ -179,7 +187,7 @@ function sendBidRequestToGa(bid) { | |||
if (bid && bid.bidderCode) { | |||
_analyticsQueue.push(function () { | |||
_eventCount++; | |||
window[_gaGlobal]('send', 'event', _category, 'Requests', bid.bidderCode, 1, _disibleInteraction); | |||
window[_gaGlobal]( trackerSend, 'event', _category, 'Requests', bid.bidderCode, 1, _disibleInteraction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trackerSend
is undefined when this function is called, you probably want a local variable for it. Also the test needs to be updated with the exported trackerSend
-- though I believe that is the only case where the export is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@protonate not sure how that happens. Shouldn't enableAnalytics
always get called before this function, therefore setting trackerSend
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trackerSend
is defined on the options
object at line 42, it's not accessible any other way at the moment. The window[_gaGlobal]
function is called when the _analyticsQueue
is iterated in the checkAnalytics
function, so scope has changed a few times over by this point. I've attached two screenshots that illustrate this.
This could be made to work by declaring trackerSend
as a local variable in the ga
module's scope, as you do with _trackerPrefix
. Then it will be accessible to enableAnalytics
and all the sendToGa
functions.
allow configuring ga tracker name and add some tests add ga spec coding style updates update prefixedSend usage use trackerSend instead of prefixedSend fix tests
Sorry - fixed specs. |
Fixed undefined error and merged manually with this commit: 3551d9e Thanks for contributing to Prebid.js. |
See issue #291