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

Added decimal/thousand separator specification when sending Analytics4 data #3366

Merged
merged 2 commits into from
Jul 7, 2023

Conversation

fballiano
Copy link
Contributor

@fballiano fballiano commented Jul 6, 2023

when product price is higher than a thousand EUR, it gets sent to analytics this way:

"currency":"EUR","value":"4,245.42"

This PR removes the thousand separator, so that it gets sent this way:

"currency":"EUR","value":"4245.42"

This PR also adds "quantity" to the begin_checkout data, which was missing.

@fballiano
Copy link
Contributor Author

@empiricompany

@github-actions github-actions bot added the Component: GoogleAnalytics Relates to Mage_GoogleAnalytics label Jul 6, 2023
@pquerner
Copy link
Contributor

pquerner commented Jul 6, 2023

Makes we wonder why we still not send the 'correct' data type to google. What if we take a look at other shops GA4 implementation and see what we can see?

@fballiano
Copy link
Contributor Author

why are you saying we don't send the correct data types?

@pquerner
Copy link
Contributor

pquerner commented Jul 6, 2023

Do you remember #3228 ?

@fballiano
Copy link
Contributor Author

If only I had the memory for all the PRs 😅 anyway that's been solved, right?

@pquerner
Copy link
Contributor

pquerner commented Jul 6, 2023

Yes it was, although the issue is still present and we are working on good faith that the data gets somewhere parsed correctly. Either in js, or in the transfer to google, or at google before it gets to a "event status". I dont know how to explain.

But this purchase data for instance, we still send the value key with "number_format" (a string) instead of the wanted "Number" (whatever that means, thanks google, but it surely doesnt mean "String", because otherwise it would be stated like that):

image

source: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#purchase

@fballiano
Copy link
Contributor Author

at the end of the day we're sending a json so the typing is kinda loose. yes the values are within quotes but I don't think that's a problem for google. and I can't find any documentation for that "Number" data type.

@pquerner
Copy link
Contributor

pquerner commented Jul 6, 2023

Yes, but we also don't have examples (do we?) by Google that shows how to properly seperate prices in their thousands or more. So again, good faith that it works. Right?

@fballiano
Copy link
Contributor Author

there are some examples in the doc, but the prices shown are smaller than a thousand. I am sure that the number_format of this PR works, the "," as thousand separator I've many doubts.

@empiricompany
Copy link
Contributor

i'm testing the two formats version

gtag('event', 'purchase', {"currency":"USD","transaction_id":"302000011","value":"4,245.42","coupon":"","shipping":"0.00","tax":"0.00","items":[{"item_id":"test-over1000","item_name":"test over 1000","quantity":1,"price":"4,245.42","discount":"0.00","item_category":"New Arrivals"}]});

gtag('event', 'purchase', {"currency":"USD","transaction_id":"302000012","value":"4245.42","coupon":"","shipping":"0.00","tax":"0.00","items":[{"item_id":"test-over1000","item_name":"test over 1000","quantity":1,"price":"4245.42","discount":"0.00","item_category":"New Arrivals"}]});

tomorrow i can say if change something / is irrilevant / or whatever..

i don't think google check data type in json if is float or string

@pquerner
Copy link
Contributor

pquerner commented Jul 6, 2023

There is a debug mode but you will see that the data looks a-like.

@empiricompany
Copy link
Contributor

once again, the debug mode is not reliable. The only way to verify that the data is being interpreted correctly is to wait for 24 hours and check how the data is being read by Analytics -> Reports or with Looker Studio

anyway...
immagine
immagine

immagine
immagine

@fballiano
Copy link
Contributor Author

There's another problem here, the "add_product_to_cart" doesn't pass the added quantity, there are cases where the website has a minimum quantity, so the current implementation is wrong.

@empiricompany
Copy link
Contributor

There's another problem here, the "add_product_to_cart" doesn't pass the added quantity, there are cases where the website has a minimum quantity, so the current implementation is wrong.

but sales_quote_add_item event is fired if minimium qty is not met?

track qty in add_to_cart is not supported in current implementation cause the observer save only product id that will be catched in observer
if we want to track add_to_cart qty for product we have to refactor it
from a quick view in observer we can save an array like sku => qty to track qty

@fballiano
Copy link
Contributor Author

it doesn't actually matter if it's fired of not, the observer doesn't carry the quantity data so I think google assumes it's "1", which is wrong

@empiricompany
Copy link
Contributor

it doesn't actually matter if it's fired of not, the observer doesn't carry the quantity data so I think google assumes it's "1", which is wrong

ok so a possible solution is to store in session key pairs
sku => qty

@fballiano
Copy link
Contributor Author

I think it would be better to store the quote_item, it least we don't need another catalog/product->load()

also, that event is not fired correctly for the project I'm working on (ajax add to cart modules), so I'd explore checkout_cart_product_add_after and/or sales_quote_product_add_after

@empiricompany
Copy link
Contributor

empiricompany commented Jul 7, 2023

so seems to be correct remove thousand separator

#302000011: "value":"4,245.42"
#302000012: "value":"4245.42"

immagine

PS: sorry for screen in Italian, i can't change the language

@fballiano fballiano merged commit 0ad042a into OpenMage:main Jul 7, 2023
15 checks passed
@fballiano fballiano deleted the ga4_numberformat branch July 7, 2023 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: GoogleAnalytics Relates to Mage_GoogleAnalytics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants