Question about customizing GA4 #3432
Replies: 3 comments 5 replies
-
we should add an event, we just didn't do it yet because we needed this kind of feedback, let me know what would be the best solution for you and let's turn it into a PR :-) |
Beta Was this translation helpful? Give feedback.
-
I think that the data array for each event emitted for GA4 should be added in a transport object that can be modified as objects are passed by reference but arrays are passed by value then the final result should be the encoded value of the data array inside the transport object. For example Varien_Object $transport Then $transport->setData('ga4_data', $eventDataArray) Then the observer class can modify the We could name the observer events based on the google event name for avoiding confusion. E.g.
What do you think? |
Beta Was this translation helpful? Give feedback.
-
I have one more consideration for this implementation aside from the data themselves. The functions are restricted using the controller name. In many installations we'll see onestep checkout extensions which will actually change the controller name. For example
This one may not work. However we have no way to reuse it either. So again we have to resort to rewriting the whole block to actually achieve a modification. Shouldn't those functions be moved to a helper instead so that they can be reused later on? For example
I guess we can also override and extend the block and just modify the layout.xml to include our own custom block instead of the original one but still we have to modify a 300line function for just altering one area which is 20 lines of code. I do think that the subactions should be their own protected functions for easier manipulation. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I noticed a thing about GA4 purchase event
It seems this function doesn't take into account the possibility of custom fees that may affect the data.
For example cash on delivery fees, payment method fees additional shipping and handling fees.
In that case the only thing we can do is rewrite the whole block to customize the function to render the correct data.
Would it be possible to add an observer event here with a transport object that carries the $orderData before
$result[] = "gtag('event', 'purchase', " . json_encode($orderData, JSON_THROW_ON_ERROR) . ");";
So that we can add our own logic and modify the orderData?
Beta Was this translation helpful? Give feedback.
All reactions