Quick question -- i'd like to improve how add to c...
# general
j
Quick question -- i'd like to improve how add to cart is being tracked on my solidus shop -- right now, the entire order gets sent each time something is added which is bloating the values in google analytics etc -- anyone have a recommendation to only send an add to cart for the specific item which was added? Anyone else faced / thought about a similar issue?
j
I'm not sure about the specifics of your setup, but if you're following the normal eCommerce events, you should only be sending the added items to events like
add_to_cart
. https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtag#add_or_remove_an_item_from_a_shopping_cart
j
totally... The solidus events gem is missing an add to cart so i adopted the started checkout, but i'm realizing now it's sending the full order details each time.. I'm going to modify one which sends only the specific line item now. It's a little tricky cause it's hard to tell the adjustments and the final total the line item based on the cart
also from the cart edit page
@line_item
appears to be nil 🤔
a
Wouldn't you access the line items through the order? On the cart page there would be many line items
j
yeah -- but how can i tell which line_item was the new one added to only send that to analytics
and then again it triggers removing a line item as well
but
@line_item
should exist so perhaps something is weird in my partials and data isn't passing correctly or something...
a
On the cart page? What would
@line_item
represent?
j
in populate i see this:
Copy code
@line_item = @order.contents.add(variant, quantity)
but calling @line_item from the _edit partial is nil 0.o
i think cause it then redirects to the cart path after the populate, so that variable is lost
a
Right, because there isn't a single line item on the edit page
j
so there's no way to really tell what was added / removed from the cart page itself, only in that single populate function, but then unsure how to trigger the JS there
yeah that makes sense
a
I think you want to make a custom event that triggers when you hit the populate action
j
order.line_items.last
seems a bit suspect too
i could do an event but still i don't see how i could hit GA4 & FB since it's all JS
a
I'm not sure about that. I'll check to see if anyone else here has done that. Off the top of my head you could send the GA request when someone clicks the button to add to cart. You should have all the data you need at that point?
☝🏼 1
c
We use Segment as a proxy for these events and we do this in JS on the Add to cart button. It seems to work reliably enough and you should have most of the data at that point (depending on your frontend implementation)
j
for sure -- okay i'll consider sprinkling it into the add to cart side -- we've got a lot of different views and buttons all spread out the frontend is a mess so was trying to avoid that 😅
but fair enough
c
What do you render on the callback to add to cart? You could also throw it in there
There are different ways to do this depending on what your frontend looks like, if you are using API to add to cart etc.
s
You could use custom event tracking for any of these behaviors you wish to track using google tag manager + GA4 connections. For example if you want to track deletions from the cart just setup onclick or whatever based trigger GTM call when that behavior is done. Than you pass all the values you want to GA4. From there you can use Bigquery to tie this to your Solidus DB data and run detailed reporting
sg horns 1