nystudio107 / craft-instantanalytics-ga4

Instant Analytics brings full Google GA4 server-side analytics support to your Twig templates and automatic Craft Commerce integration
Other
3 stars 4 forks source link

How to track viewed_items / purchased_items #22

Closed carolineboeykens closed 10 months ago

carolineboeykens commented 10 months ago

Question

We've installed the plugin, but we're struggling to receive all data in Google Analytics 4. Currently the events add/remove_item_to_cart are being tracked, as well as the parameters of item_type (meaning we can see which items were added to the cart), which is already great! However, viewed_items and purchased_items are not being pushed to GA4. It's also important to us that the currency/cost of the products are tracked as well.

Do you perhaps know how we can fix these issues? Do we need to track this with other events?

Many thanks in advance!

khalwat commented 10 months ago

Can you provide some more clarity?

1) vieweded_items - not sure what you mean. If it's https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#view_item, then you would trigger that using {% do instantAnalytics.addCommerceProductImpression(productOrVariant) %} in Twig.

2) purchased_items - not sure which event this is, either. If you mean https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#purchase, then that is triggered on order complete. If you are inquiring about why this is not showing up User Purchase Journey, then that's likely because it's a closed funnel report and requires certain events to happen in a sequence and it's likely that you are missing the required "Being checkout" event, which you can trigger with {% do instantAnalytics.beginCheckout(craft.commerce.carts.cart) %} in Twig where you actually begin the checkout process. (More info about the report can be found here - https://support.google.com/analytics/answer/13128171?hl=en)

carolineboeykens commented 10 months ago

Thank you for the information!

We were looking at the Ecommerce purchases table in GA4. Here we are missing the information about the Items viewed and Items purchased.

Schermafbeelding 2023-10-31 om 10 04 37

Would this event help this to get the right data? {% do instantAnalytics.addCommerceProductImpression(currentVariant) %}

The items purchased should already be included according to the documentation:

Purchase - When someone completes a purchase in your Craft Commerce store. This will include all of the LineItems that were added to the cart, as well as the Order Reference, Revenue, Tax, Shipping, and Coupon Code used (if any).

https://nystudio107.com/docs/instant-analytics-ga4/using.html#plugin-interaction

khalwat commented 10 months ago

Would this event help this to get the right data?

{% do instantAnalytics.addCommerceProductImpression(currentVariant) %}

This would be the right one

The items purchased should already be included according to the documentation:

That's true. Can you check if the purchase event is coming in? Another thing you can do is make sure you are firing the begin_checkout when starting the checkout process by doing:

{% do instantAnalytics.beginCheckout(craft.commerce.carts.cart) %}

in the Twig template where appropriate

carolineboeykens commented 10 months ago

Yes, it works! Thank you!