Skip to content
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

Add Google Analytics 4 and Universal Analytics Ecommerce translation layer #1170

Merged

Conversation

igneel64
Copy link
Contributor

@igneel64 igneel64 commented Apr 3, 2023

Additional plugin utility functions to be paired up with the GA4-UA-ee capability https://deploy-preview-14--snowplow-axl-ecom.netlify.app/accelerators/ecommerce/tracking/ua_ga4_migration/

@igneel64 igneel64 marked this pull request as draft April 3, 2023 06:42
@miike
Copy link
Contributor

miike commented Apr 5, 2023

This looks good to me, adding @jethron to have a look through too.

@miike miike requested a review from jethron April 5, 2023 22:55
Copy link
Contributor

@jethron jethron left a comment

Choose a reason for hiding this comment

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

Looks like handy wrappers, thanks @igneel64! I think the single object arg vs multiple args is the only big thing I'd change. Maybe currency after that.

plugins/browser-plugin-snowplow-ecommerce/src/ua/api.ts Outdated Show resolved Hide resolved
plugins/browser-plugin-snowplow-ecommerce/src/ua/api.ts Outdated Show resolved Hide resolved

export function transformUAProductsToSPProducts({
products,
currencyCode = 'USD',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a reasonably sane default, but it's unfortunate that it has different semantics to undefined currency in GA... I think currencyCode was a relatively late addition to the ecommerce definition so a few implementations will not have it there and just use their single property-level currency so this isn't gonna be very compatible.

Would be nice if you could pass in a defaultCurrencyCode or something when you install the plugin and have that be used instead, probably a broader scope than this PR though. Failing that, it's annoying but maybe this should be an optional param in all the callers of these util functions so it can at least be easily hardcoded in GTM without needing a dataLayer update (which may involve a different team for our users).

export function trackGA4SelectPromotion(ecommerce: GA4EcommerceObject) {}
export function trackGA4ViewCart() {}

export function trackGA4AddToCart(ecommerce: GA4EcommerceObject & Currency, finalCartValue: number) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to follow the normal v3 idiom of just taking a single object parameter instead of multiple ones?
Currently we lose the ability to specify contexts etc that the wrapped trackAddToCart function & co has.
Maybe that's a good incentive to do a native implementation.

Copy link
Contributor Author

@igneel64 igneel64 Apr 17, 2023

Choose a reason for hiding this comment

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

Yeap, as advertised in the accelerator page, this is a 'quick' way to migrate your most important GA ecommerce events to snowplow using these wrappers. If you are at a level of custom contexts on ecommerce events, then I think it is a good place to start the native migration.

I think this would be the point where the user would like to add their custom dimensions in a context, sent together with the standard snowplow ecommerce attributes.

Kinda torn again, it would be really easy make the second argument an options object which would include the required attributes, where needed e.g. finalCartValue, and the addition of custom contexts and tracker selection (will probably do that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jethron
Added a simple options argument which for now reference the currency where required and any other attribute which is required in some cases. I believe that for now it is good enough for the simple translation layer and the extra contexts etc. could be a ticket to the native implementation.

plugins/browser-plugin-snowplow-ecommerce/src/ga4/api.ts Outdated Show resolved Hide resolved
@igneel64 igneel64 changed the base branch from master to release/3.10.0 April 17, 2023 07:06
@igneel64 igneel64 force-pushed the feature/snowplow-ecommerce-ga4-ee-migration-apis branch from ad02159 to 90375ab Compare April 17, 2023 11:33
@bundlemon
Copy link

bundlemon bot commented Apr 17, 2023

BundleMon

Files added (6)
Status Path Size Limits
libraries/browser-tracker-core/dist/index.mod
ule.js
+24.52KB 25KB / +10%
trackers/javascript-tracker/dist/sp.js
+23.84KB 25KB / +10%
trackers/javascript-tracker/dist/sp.lite.js
+14.53KB 15KB / +10%
trackers/browser-tracker/dist/index.umd.min.j
s
+14.4KB 15KB / +10%
libraries/tracker-core/dist/index.module.js
+13.35KB 15KB / +10%
trackers/browser-tracker/dist/index.module.js
+3.46KB 5KB / +10%

Total files change +94.09KB 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history

@igneel64 igneel64 force-pushed the feature/snowplow-ecommerce-ga4-ee-migration-apis branch from 90375ab to 223930c Compare April 17, 2023 14:09
@igneel64 igneel64 force-pushed the feature/snowplow-ecommerce-ga4-ee-migration-apis branch from 223930c to 1877ba8 Compare April 17, 2023 14:34
@igneel64 igneel64 marked this pull request as ready for review April 21, 2023 09:43
@igneel64 igneel64 requested a review from jethron April 25, 2023 09:04
@igneel64 igneel64 force-pushed the feature/snowplow-ecommerce-ga4-ee-migration-apis branch from d70353b to cb13d3b Compare May 1, 2023 13:19
@igneel64 igneel64 requested a review from jethron May 2, 2023 07:13
Copy link
Contributor

@jethron jethron left a comment

Choose a reason for hiding this comment

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

Almost there... 😛

@igneel64 igneel64 force-pushed the feature/snowplow-ecommerce-ga4-ee-migration-apis branch from cb13d3b to 7bf4d6d Compare May 9, 2023 08:13
@igneel64 igneel64 merged commit 44d2d25 into release/3.10.0 May 9, 2023
2 checks passed
@igneel64 igneel64 deleted the feature/snowplow-ecommerce-ga4-ee-migration-apis branch May 9, 2023 09:16
@igneel64 igneel64 mentioned this pull request May 9, 2023
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.

None yet

4 participants