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

Allow unknown product keys for product details #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wuservices
Copy link
Contributor

Adds additional item parameter mappings for GA4 ecommerce including category2-5, which fixes #3.

Parameters from: https://www.thyngster.com/ga4-measurement-protocol-cheatsheet/

@wuservices
Copy link
Contributor Author

If we're able to send nested categories to GA4, but other tools only accept a single category, what do you think of allowing sending category1 to optionally override category here?

Use case:

You have a 3-level hierarchy: Parent/Child/Grandchild. This is the category you would send to most tools, which only accept a single level. However, if you had that, and also defined category2=Child, category3=Grandchild, now there's not really a way to say that category=Parent for GA4 (or other tools that handle nested categories). I propose we could also add a category1, so that you can set category1=Parent, which will be used instead of category if the tool supports multiple levels and if it's defined.

This isn't in the PR, currently as I wanted to see what you thought given this has potential implications for all ecommerce tools.

@bjesus
Copy link
Member

bjesus commented Dec 19, 2022

hey @wuservices ! I'm concerned that this change is actually not about extending the GA4 component per se, but rather, it is extending the Ecommerce API. Allowing keys like category2 in the Ecommerce API would mean that we'd need to figure out how to support them with other tools too, and we generally trying to avoid changing the API just to accommodate one specific tool.

Nothing generally prevents you from adding custom keys to the payload when calling zaraz.ecommerce, so for example doing something like zaraz.ecommerce("Product Added", {category: "shirts", ca2: "polo"}) is perfectly doable. The issue is that currently Zaraz will see this as a custom field and will therefore prepend ep. to the key name, and I suspect it will then end in the wrong place. However, I believe that this can be fixed by setting a specific logic for these specific keys, specifically on ecommerce events. By doing that, users will be able to use ca2, ca3 etc when they're calling zaraz.ecommerce, but the Ecommerce API itself will change.

Does that make sense?

@wuservices
Copy link
Contributor Author

wuservices commented Dec 21, 2022

Hi @bjesus thanks for taking a look. I agree this could be a bigger discussion if thinking about extending the Ecommerce API completely, especially because nested categories is a feature that most APIs will lack and it's also something that each provider is likely to have a slightly different model for.

However, I think the idea of adding custom keys is a general need here and would be a good strategy to handle in general. My understanding of the current code is that buildProductRequest only maps in the known keys and everything else is discarded. Is ep. only used for extra keys at the root vs in items?

One concern with adding custom keys for each item and blindly mapping them to each tool is that some tools may not like the extra keys (hypothetically at least). Would it be helpful to namespace additional custom keys and have a way to pass them in both at the root and for any products array?

zaraz.ecommerce('Product List Viewed', {
  products: [
    { 
      product_id: '999555321',
      sku: '2671033',
      name: 'V-neck T-shirt',
      brand: 'Cool Brand',
      variant: 'White',
      price: 14.99,
      currency: 'usd',
      value: 18.99, 
      position: 1,
      category: 'T-shirts',
      _ga4_ca2: 'polo',
    }
  ]
})

@bjesus
Copy link
Member

bjesus commented Feb 14, 2023

Hey @wuservices, ep. and epn. are indeed only used for root extra keys. We will accept a PR that keeps unused products keys in the products array sent to GA4. will that solve your issue?

@wuservices wuservices changed the title Add ecommerce item category, discount, affiliation, position mappings Allow unknown product keys for product details May 19, 2023
@wuservices
Copy link
Contributor Author

@bjesus I think accepting unknown keys for product data would be pretty flexible. It also seems like it'd simplify the code a bit.

I updated the PR with what I think this would look like.

@wuservices
Copy link
Contributor Author

@bjesus just checking in here. Do the updated changes look like what you had in mind? Happy to tweak if needed. Thanks!

@wuservices
Copy link
Contributor Author

We will accept a PR that keeps unused products keys in the products array sent to GA4. will that solve your issue?

@bjesus @simonabadoiu how does the proposed change look?

The idea is that there is no longer an allowlist for PRODUCT_DETAILS so all will get sent. This would allow item attributes unsupported by Zaraz ecommerce to be sent, including any custom item level custom dimensions. I didn't have a great way to test this though.

src/ecommerce.ts Outdated Show resolved Hide resolved
Allows unknown (to Zaraz e-commerce) keys that could be valid for GA4, such as `'ca2'`, `'ca3'`, `'ca4'`, `'ca5'`, `'ds'`, `'af'`, `'lp'` to be added to the GA4 result.
Removes product details mapping, which is unnecessary now that unknown keys are accepted.
Copy link
Contributor

@simonabadoiu simonabadoiu left a comment

Choose a reason for hiding this comment

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

Hi, the code looks good to me. We're just making sure it makes sense when it comes to the MC standard and we should be good to go

@kuba-orlik kuba-orlik assigned bjesus and unassigned simonabadoiu Sep 6, 2023
@wuservices
Copy link
Contributor Author

@bjesus does this look good? It seems like this will also allow users to add custom item-scoped custom parameters too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update ecommerce for GA4 item category hierarchy spec
4 participants