nystudio107 / craft-instantanalytics

DEPRECATED: Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
https://nystudio107.com/
Other
20 stars 9 forks source link

addCommerceCheckoutStep doesn't appear to be working #60

Closed peteeveleigh closed 2 years ago

peteeveleigh commented 3 years ago

Hi, Firstly, sorry if this is a little vague. I'm working a bit blind. Another agency is handling analytics integration into one of our sites and I can't see what they have set up. However, they are highly experienced and I'm not doubting their end of things.

We are trying to add checkout steps via Instant Analytics. We've successfully added page view, product views, list views etc and these are showing up within Analytics. But the checkout steps are not. I've been tinkering with this for a while and cannot see what is wrong.

The Checkout step is being added thus;

{% do instantAnalytics.addCommerceCheckoutStep(cart, 1) %}

Looking at the debug toolbar does show that the addCommerceCheckoutStep method is being called and appears successful. But it's showing after the pageView is sent and the response received (see screenshot). Is this correct?

I may well be misunderstanding things but shouldn't the checkoutStep be added to the pageView data?

Screenshot 2021-09-14 at 17 10 19

khalwat commented 3 years ago

hmmmm I wouldn't think it should happen after that -- how is the analytics information being sent along? Are you doing it automatically?

peteeveleigh commented 2 years ago

We have IA's auto pageview send turned off and are using the {% hook 'iaSendPageView' %} on the main layout template. I guess I can try it with the auto send turned on but we disabled it as we were finding that error templates were showing up in the stats which was undesirable. So the error templates now set a variable that prevents the IA Hook from being rendered. I was thinking that maybe this variable was being passed to the layout somewhere on the checkout steps but that doesn't seem to be the case.

We've also got SEOmatic installed with Google Tag Manager enabled. The Script template has been hardcoded to us a GTM staging environment set up by aforementioned marketing agency while we get everything working as required. Screenshots attached.

Screenshot 2021-09-15 at 12 18 22

Screenshot 2021-09-15 at 12 18 33

peteeveleigh commented 2 years ago

Is there something I can do here? I just can't seem to get the checkout step data passed through to Google

khalwat commented 2 years ago

Here's what I think is happening.

I think that Twig is parsing this hook:

{% hook 'iaSendPageView' %}

before it is parsing your code that adds the step:

{% do instantAnalytics.addCommerceCheckoutStep(cart, 1) %}

Check out the article "Twig Processing Order & Scope" for details on the order in which these things happen: https://nystudio107.com/blog/twig-processing-order-and-scope

...but the TL;DR is that the code in the layout template will be executed first, IF it isn't in a {% block %} so you might try moving the hook into a block.