- Posts: 127
- Thank you received: 3
Google analytics, event settings on checkout
6 years 4 months ago - 6 years 4 months ago #319805
by zetap
Replied by zetap on topic Google analytics, event settings on checkout
Good Morning
Perfect, but this does not affect the tracking of the "next" buttons, the code would be copied below.
A question that arises for me is: are the gtag statements executed when the buttons are clicked or when the buttons are loaded on the page? because I detect follow-up of the button to finish the purchase (step == 4), as it was clicked 4 times on it, but there are no purchases in the hikashop panel
Thank you very much, greetings!
Perfect, but this does not affect the tracking of the "next" buttons, the code would be copied below.
A question that arises for me is: are the gtag statements executed when the buttons are clicked or when the buttons are loaded on the page? because I detect follow-up of the button to finish the purchase (step == 4), as it was clicked 4 times on it, but there are no purchases in the hikashop panel
Code:
window.Oby.registerAjax (['checkoutFormSubmit', 'checkoutBlockSubmit'], function (params) {
var mainDiv = document.getElementById ('hikashop_checkout');
var step = mainDiv.getAttribute ('data-checkout-step');
if (step == 1) {
gtag ('event', 'next_buy', {'event_category': 'payment_process', 'event_label': 'next_buy'});
}
if (step == 2) {
gtag ('event', 'next_session_start', {'event_category': 'paid_process', 'event_label': 'next_session_start'});
}
if (step == 3) {
gtag ('event', 'next_address', {'event_category': 'payment_process', 'event_label': 'next_address'});
}
if (step == 4) {
gtag ('event', 'final_payment_method', {'event_category': 'paid_process', 'event_label': 'finalize_payment_method'});
}
});
Last edit: 6 years 4 months ago by nicolas.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319810
by nicolas
Replied by nicolas on topic Google analytics, event settings on checkout
Hi,
With this code, the gtag call is only done when the button is pressed, not when the page is loading.
Now, if an error happens (for example, the customer didn't check the Terms and Conditions checkbox), then the server will refuse the creation of the order and even though gtag will be triggered, the order won't be created. So it's totally normal.
You should add an additional gtag call in the checkout / after_end.php view file, which displays the "thank you" page when the customer comes back from the payment gateway and potentially another one in checkout / end.php which displays the redirection page when the customer goes to the payment gateway.
With this code, the gtag call is only done when the button is pressed, not when the page is loading.
Now, if an error happens (for example, the customer didn't check the Terms and Conditions checkbox), then the server will refuse the creation of the order and even though gtag will be triggered, the order won't be created. So it's totally normal.
You should add an additional gtag call in the checkout / after_end.php view file, which displays the "thank you" page when the customer comes back from the payment gateway and potentially another one in checkout / end.php which displays the redirection page when the customer goes to the payment gateway.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319867
by zetap
Replied by zetap on topic Google analytics, event settings on checkout
Hello
Of course I understand, it worked perfectly.
Now, what is not clear to me is about adding the JS code in the PHP view, in the end.php view would I have to add a hidden html tag that in the onload event of the page calls a JS function that executes the gtag sentence?
Thanks greetings !
Of course I understand, it worked perfectly.
Now, what is not clear to me is about adding the JS code in the PHP view, in the end.php view would I have to add a hidden html tag that in the onload event of the page calls a JS function that executes the gtag sentence?
Thanks greetings !
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319870
by nicolas
Replied by nicolas on topic Google analytics, event settings on checkout
Hi,
In the code of the view, at the beginning, before anything else, you can directly add:
and the JS wil run on that page when it loads.
You can wrap your JS in an onload event so that it runs only after the script files are loaded (and mainly the one creating the gtag function
In the code of the view, at the beginning, before anything else, you can directly add:
Code:
<script>... your JS ... </script>
You can wrap your JS in an onload event so that it runs only after the script files are loaded (and mainly the one creating the gtag function
Please Log in or Create an account to join the conversation.
6 years 4 months ago #319918
by zetap
Replied by zetap on topic Google analytics, event settings on checkout
Good Morning
Great, it's very clear to me.
Thank you very much for your great help
Great, it's very clear to me.
Thank you very much for your great help
Please Log in or Create an account to join the conversation.
Time to create page: 0.190 seconds