[Skip to main content](#vessel-content)

#   Google analytics, event settings on checkout

##

- **[zetap](/forum/user/44792-zetap "View zetap's Profile")**
- [![zetap's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/44792-zetap "View zetap's Profile") Topic Author
- [ Offline](/forum/user/44792-zetap)

Less More

- Posts: 127
- Thank you received: 3
-
-

6 years 6 months ago -  6 years 6 months ago [\#319805](#319805) by [zetap](/forum/user/44792-zetap "View zetap's Profile")  Replied by *[zetap](/forum/user/44792-zetap "View zetap's Profile")* on topic *[Google analytics, event settings on checkout](/forum/27-checkout/899879-google-analytics-event-settings-on-checkout?start=20#319805 "-- url of the page with the problem -- :   www.abierto.uy  -- HikaShop version -- : 4.3.0 -- Joomla version -- : 3.9.18 -- PHP version -- : 7.3  Hello  We are starting to implement google analytics on the site, for which the marketing agency asks me to icluid certain JS codes on the buttons of the purchase process, the &quot;next&quot; button of the purchase process. With JavaScript, the click event of the link or button is captured, but in order to capture it, the event uses the css class or the element id. It happens that all the &quot;next&quot; buttons, from each step of the purchase process are the same, same css class and same item id.  My query is, do I have any way that each &quot;next&quot; button of the purchase process has at least one extra class of css different for each one, so that I can capture each click that the user gives and in this way Know how many begin the purchase process, how much they abandon the purchase process and how many finish it.  In addition, I would like to tell you to check the documentation about the google analytics plugin that includes hikashop, but it is not what you are needing at the moment.   www.hikashop.com/support/documentation/2...oogle-analytics.html  Thank you !")*

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 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'}); } });

Thank you very much, greetings!

Last edit: 6 years 6 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTg3OS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXNldHRpbmdzLW9uLWNoZWNrb3V0P3N0YXJ0PTIwJnRtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

6 years 6 months ago [\#319810](#319810) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Google analytics, event settings on checkout](/forum/27-checkout/899879-google-analytics-event-settings-on-checkout?start=20#319810 "-- url of the page with the problem -- :   www.abierto.uy  -- HikaShop version -- : 4.3.0 -- Joomla version -- : 3.9.18 -- PHP version -- : 7.3  Hello  We are starting to implement google analytics on the site, for which the marketing agency asks me to icluid certain JS codes on the buttons of the purchase process, the &quot;next&quot; button of the purchase process. With JavaScript, the click event of the link or button is captured, but in order to capture it, the event uses the css class or the element id. It happens that all the &quot;next&quot; buttons, from each step of the purchase process are the same, same css class and same item id.  My query is, do I have any way that each &quot;next&quot; button of the purchase process has at least one extra class of css different for each one, so that I can capture each click that the user gives and in this way Know how many begin the purchase process, how much they abandon the purchase process and how many finish it.  In addition, I would like to tell you to check the documentation about the google analytics plugin that includes hikashop, but it is not what you are needing at the moment.   www.hikashop.com/support/documentation/2...oogle-analytics.html  Thank you !")*

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.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTg3OS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXNldHRpbmdzLW9uLWNoZWNrb3V0P3N0YXJ0PTIwJnRtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[zetap](/forum/user/44792-zetap "View zetap's Profile")**
- [![zetap's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/44792-zetap "View zetap's Profile") Topic Author
- [ Offline](/forum/user/44792-zetap)

Less More

- Posts: 127
- Thank you received: 3
-
-

6 years 6 months ago [\#319867](#319867) by [zetap](/forum/user/44792-zetap "View zetap's Profile")  Replied by *[zetap](/forum/user/44792-zetap "View zetap's Profile")* on topic *[Google analytics, event settings on checkout](/forum/27-checkout/899879-google-analytics-event-settings-on-checkout?start=20#319867 "-- url of the page with the problem -- :   www.abierto.uy  -- HikaShop version -- : 4.3.0 -- Joomla version -- : 3.9.18 -- PHP version -- : 7.3  Hello  We are starting to implement google analytics on the site, for which the marketing agency asks me to icluid certain JS codes on the buttons of the purchase process, the &quot;next&quot; button of the purchase process. With JavaScript, the click event of the link or button is captured, but in order to capture it, the event uses the css class or the element id. It happens that all the &quot;next&quot; buttons, from each step of the purchase process are the same, same css class and same item id.  My query is, do I have any way that each &quot;next&quot; button of the purchase process has at least one extra class of css different for each one, so that I can capture each click that the user gives and in this way Know how many begin the purchase process, how much they abandon the purchase process and how many finish it.  In addition, I would like to tell you to check the documentation about the google analytics plugin that includes hikashop, but it is not what you are needing at the moment.   www.hikashop.com/support/documentation/2...oogle-analytics.html  Thank you !")*

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 !

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTg3OS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXNldHRpbmdzLW9uLWNoZWNrb3V0P3N0YXJ0PTIwJnRtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

6 years 6 months ago [\#319870](#319870) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Google analytics, event settings on checkout](/forum/27-checkout/899879-google-analytics-event-settings-on-checkout?start=20#319870 "-- url of the page with the problem -- :   www.abierto.uy  -- HikaShop version -- : 4.3.0 -- Joomla version -- : 3.9.18 -- PHP version -- : 7.3  Hello  We are starting to implement google analytics on the site, for which the marketing agency asks me to icluid certain JS codes on the buttons of the purchase process, the &quot;next&quot; button of the purchase process. With JavaScript, the click event of the link or button is captured, but in order to capture it, the event uses the css class or the element id. It happens that all the &quot;next&quot; buttons, from each step of the purchase process are the same, same css class and same item id.  My query is, do I have any way that each &quot;next&quot; button of the purchase process has at least one extra class of css different for each one, so that I can capture each click that the user gives and in this way Know how many begin the purchase process, how much they abandon the purchase process and how many finish it.  In addition, I would like to tell you to check the documentation about the google analytics plugin that includes hikashop, but it is not what you are needing at the moment.   www.hikashop.com/support/documentation/2...oogle-analytics.html  Thank you !")*

Hi,

In the code of the view, at the beginning, before anything else, you can directly add: Code:

&lt;script&gt;... your JS ... &lt;/script&gt;

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 ![:)](/media/kunena/emoticons/3.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTg3OS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXNldHRpbmdzLW9uLWNoZWNrb3V0P3N0YXJ0PTIwJnRtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[zetap](/forum/user/44792-zetap "View zetap's Profile")**
- [![zetap's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/44792-zetap "View zetap's Profile") Topic Author
- [ Offline](/forum/user/44792-zetap)

Less More

- Posts: 127
- Thank you received: 3
-
-

6 years 6 months ago [\#319918](#319918) by [zetap](/forum/user/44792-zetap "View zetap's Profile")  Replied by *[zetap](/forum/user/44792-zetap "View zetap's Profile")* on topic *[Google analytics, event settings on checkout](/forum/27-checkout/899879-google-analytics-event-settings-on-checkout?start=20#319918 "-- url of the page with the problem -- :   www.abierto.uy  -- HikaShop version -- : 4.3.0 -- Joomla version -- : 3.9.18 -- PHP version -- : 7.3  Hello  We are starting to implement google analytics on the site, for which the marketing agency asks me to icluid certain JS codes on the buttons of the purchase process, the &quot;next&quot; button of the purchase process. With JavaScript, the click event of the link or button is captured, but in order to capture it, the event uses the css class or the element id. It happens that all the &quot;next&quot; buttons, from each step of the purchase process are the same, same css class and same item id.  My query is, do I have any way that each &quot;next&quot; button of the purchase process has at least one extra class of css different for each one, so that I can capture each click that the user gives and in this way Know how many begin the purchase process, how much they abandon the purchase process and how many finish it.  In addition, I would like to tell you to check the documentation about the google analytics plugin that includes hikashop, but it is not what you are needing at the moment.   www.hikashop.com/support/documentation/2...oogle-analytics.html  Thank you !")*

Good Morning

Great, it's very clear to me.

Thank you very much for your great help

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTg3OS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXNldHRpbmdzLW9uLWNoZWNrb3V0P3N0YXJ0PTIwJnRtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.054 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
