Skip to content

Conversation

@gpsamson
Copy link
Contributor

@gpsamson gpsamson commented Mar 9, 2021

What does this PR do?
This pull request introduces a new Google Analytics 4 to service the new GA4 property type which varies greatly from Universal property types. It includes functionality up to P2 in the work breakdown.

The complete spec can be found in the GA4 A.js Destination SDD.

Are there breaking changes in this PR?
No

Testing

  • Testing completed successfully in stage by manually sending events.
  • Unit tests complete

Detailed testing can be found here: https://paper.dropbox.com/doc/GA4-A.js-Test-Plan--BHKEytO0krCgb7Rq0ETLY6TBAg-hIeXHKehkOvlhqONgOGdV

Does this require a new integration setting? If so, please explain how the new setting works
A completely new definition can be found in Partner Portal for google-analytics-4

Links to helpful docs and other external resources
https://developers.google.com/analytics/devguides/collection/ga4/tag-guide is heavily referenced throughout the code.

@gpsamson gpsamson marked this pull request as ready for review March 10, 2021 21:29
Comment on lines 63 to 79
for (var i = 0; i < measurementIds.length; i++) {
config.push(['config', measurementIds[i]]);
}

// Disable Page View Measurement
// https://developers.google.com/analytics/devguides/collection/ga4/disable-page-view
if (opts.disablePageViewMeasurement) {
for (var i = 0; i < measurementIds.length; i++) {
config.push([
'config',
measurementIds[i],
{
send_page_view: false
}
]);
}
}
Copy link
Contributor

@briemcnally briemcnally Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we add the GA properties then if they have another setting enabled ie disablePageViewMeasurement push the same properties to the config with with send_page_view: false Curious if this causes any dupes? Looks like config is just an array. I.e. should we have

config.push([
    'config',
    measurementIds[i],
    { allParamtersHere}
])

It could need to be separate for a reason I am not aware, just checking 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this would cause dupes. I think it would be cleaner to push the properties once, so I can make that change.

Copy link
Contributor Author

@gpsamson gpsamson Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for calling this out! Seems when we call config multiple times it may overwrite others 🤔.

var props = page.properties();
var name = page.fullName();

// var language = ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we have or are working on a plan for language? I see in the SDD that Segment doesn't have it specced for a.js events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is part of the Segment spec which is why I left it commented. It is mapped in the SDD but I don't think it's crucial for the pilot version. I can remove for now and re-add if there are asks for it!

cookie_expires: opts.cookieExpiration,
};

var sets = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an array of objects? A little bit confused by the different format of Cookie Flags and the rest of them. Could be missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gtag.js has a set command and it's really confusing. Sometimes it accepts a single object argument (L1) and sometimes it accepts multiple arguments (L2):

window.gtag('set', { cookie_flags: opts.cookieFlags })
window.gtag('set', 'allow_google_signals', !opts.disableAllAdvertisingFeatures)

The sets var we have is an array of arrays to represent a list of set commands and the arguments to pass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha makes sense. Thanks for clarifying

* can be appended as part of the user_properties object instead of being configured by
* an explicit command.
* https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id#set_user_id
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: should we move the comment to L to be aligned

@gpsamson gpsamson requested review from brennan and briemcnally March 22, 2021 17:21
@gpsamson
Copy link
Contributor Author

@brennan @briemcnally - Jen and I went through the test plans on Friday and all functionality is working as expected. There may be changes to the setting names today, but not a drastic change in behavior.

Thanks for the reviews so far!

Copy link
Contributor

@briemcnally briemcnally left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work @gpsamson

return;
}

// Track categorized pages setting needed here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we been able to look into this? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it by Jen but no response yet. I think we can leave it out for now and add it if customers request it. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jen recommended we omit it until this functionality is requested.

var mappings = this.options.customEventsAndParameters;

for (var i = 0; i < mappings.length; i++) {
var mapping = mappings[i]; // Type check for object?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering per the comment if we should put a type check for object here?

continue;
}

var parameterMappings = mapping.parameters || []; // Type check for array?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also curious about this comment re: a type check for array. Is that something we should add?

// eg; [{ key: 'properties.genre', value: 'primary_genre }]
//
for (var j = 0; j < parameterMappings.length; j++) {
var map = parameterMappings[j] || {}; // Type check for object?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another type-check comment here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpsamson Not a big deal, but looks like we still have a type-check comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thx! I will remove it prior to merging.

parameters[param] = value;
}

window.gtag('event', googleEvent, reject(parameters));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we need reject here given line 292 above - if map. value is falsy, then we don't add the key:value pair to the parameters map in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - it's pretty redundant!

@gpsamson gpsamson requested a review from brennan March 24, 2021 20:05
@gpsamson
Copy link
Contributor Author

Thanks for the review @brennan @briemcnally :tribe:

I downgraded the version to 0.0.1 since this will be in private beta for a few weeks and we may make changes that break existing behavior (eg; default mappings).

@gpsamson gpsamson merged commit f3acb12 into master Mar 24, 2021
@dobesv
Copy link

dobesv commented Sep 29, 2021

Is there any process or timeline for this to be published to npm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants