Closed bossanova808 closed 1 year ago
@bossanova808 you should be able to get this to work by doing the following in your XHR'd templates:
{% hook 'iaSendPageView' %}
If this doesn't work for you, I will re-open.
Addressed in 4.0.0-beta.2
Tried a couple quick tests
{# ANALYTICS - need to trigger this manually as the ajax prevention stuff stops the auto sending... #}
{% if craft.app.plugins.isPluginEnabled('instant-analytics-ga4') %}
{% do instantAnalytics.triggerOrderCompleteEvent(order) %}
{% endif %}
...
{# ANALYTICS - beacuse we do ajax paymnt, force this to be submitted as if AutoSendPageViews is off #}
{% block tail %}
{{ parent() }}
{% if craft.app.plugins.isPluginEnabled('instant-analytics-ga4') %}
{% hook 'iaSendPageView' %}
{% endif %}
{% endblock %}
..but not seeing a purchase resulting at the GA end still.
(Not seeing any user data either yet despite those client_id changes).
Am actually about to go away for ~10 days, so will have to check back on progress after that. Hopefully other folks will have started to dig in by then.
(I presume that this line:
{% do instantAnalytics.triggerOrderCompleteEvent(order) %}
is not actually needed - the idea being IA is creating a purchase event (when listening to the Commerce event) - so really just that hook is needed to force send it, right?)
Right only the hook should be needed. I will re-open this so we can double-check it.
For completeness, here are the events that automatically fire from Commerce events:
// Commerce-specific hooks
if (self::$commercePlugin !== null) {
Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function (Event $e): void {
$order = $e->sender;
if (self::$settings->autoSendPurchaseComplete) {
$this->commerce->triggerOrderCompleteEvent($order);
}
});
Event::on(Order::class, Order::EVENT_AFTER_ADD_LINE_ITEM, function (LineItemEvent $e): void {
$lineItem = $e->lineItem;
if (self::$settings->autoSendAddToCart) {
$this->commerce->triggerAddToCartEvent($lineItem);
}
});
// Check to make sure Order::EVENT_AFTER_REMOVE_LINE_ITEM is defined
if (defined(Order::class . '::EVENT_AFTER_REMOVE_LINE_ITEM')) {
Event::on(Order::class, Order::EVENT_AFTER_REMOVE_LINE_ITEM, function (LineItemEvent $e): void {
$lineItem = $e->lineItem;
if (self::$settings->autoSendRemoveFromCart) {
$this->commerce->triggerRemoveFromCartEvent($lineItem);
}
});
}
}
Ok, so vis a vis discussion about the ajax blocking the sending of my add to cart, remove from cart, and purchase events, meaning I am not seeing any purchases come through...I am now trying to do this manually but without re-implementing the entire wheel.
In my order complete template I have:
And in the bottom the layout I have
But...this does not work - no event is sent to GA4. I added some logging code to
triggerOrderCompleteEvent
and that's not coming out either.Obviously I can add my own code to create and send the event but right now I am already doing that for all of these events manually:
(I am doing those via via my own service in PHP because doing it all in Twig is just harder/messier - those are working ok, although I can't see the lineItem data in GA4 when looking at the begin checkout event, even though I am adding it:
(I'd use your function to add the lineItem data but it's
protected
.)Thus, since the ajax change, the only things I have actually got going to GA4 from IA with the 'it just works' approach are: