PrestaShop / ganalytics

Gain clear insights into important metrics about your customers, using Google Analytics in PrestaShop 1.6.
10 stars 44 forks source link

[-] MO ganalytics Fixes 78 checkout steps not being sent to google Analytics #90

Closed pierreavizou closed 8 years ago

pierreavizou commented 8 years ago

Google Analytics ecommerce data has to be sent along with a hit, like pageview or event. However, for some reason, the pageview hit inserted in a separate <script> tag (in _getGoogleAnalyticsTag()) is often sent before the ecommerce data is set, resulting in no checkout steps being sent.

Since checkout steps do not send an event hit type in the JS lib, we need to send a pageview hit right after setting the ecommerce data. We also set $js-state to 1 in the hookFooter for checkout pages so that there is no duplicate pageview sent to Google Analytics.

cedricfontaine commented 8 years ago

It's probably related to a previous request, cause it was working before. I'm not sure we should add pageview outside of the main scope, cause we had a lot of bug with pageview sent 2 times. I'll look for the request that broke this.

pierreavizou commented 8 years ago

Thanks for the feedback. Actually I believe there is no risk to send pageview twice when we set $js_state to 1 correctly, because this prevents the ga('send', 'pageview') from being injected into the template by the _runJs() function. It's great if you can find a previous PR that broke this and then revert it, otherwise my PR is here to help. :)

cedricfontaine commented 8 years ago

Could it be linked to #71 ?

pierreavizou commented 8 years ago

Yes I think it is, because prior to #71, ecommece data configuration and pageview hit sending were done in the same <script> tag, which this PR has divided into two tags, which causes the pageview hit to be sent before ecommerce data configuration. It's not possible to affirm this with certainty without testing (G.A. can be tricky sometimes), but my guess is that #71 is indeed responsible for introducing the bug.

cedricfontaine commented 8 years ago

So either we revert and we will have false positive about code not detected, either the steps does not work.

pierreavizou commented 8 years ago

Seems like neither is truly a good option :/ I think that the modification in my PR solves both issues. It does not seem to be a problem to send pageview hits within the JS Lib, because thanks to the $js_state variable, we can prevent it from being sent a second time from the _runJs() function. Actually from looking at it, it seems that it's for this kind of use cases that this variable was implemented. That's why I felt it would be fine to use it in order to solve this issue.

Quetzacoalt91 commented 8 years ago

Hi @pierreavizou,

Thanks, your PR has just been merged and a new version will be released for tomorrow.

Best regards