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

#   I wish to trigger a Google Analytics Event when someone select "Add to Cart"

##

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

Less More

- Posts: 190
- Thank you received: 2
-
-

7 years 9 months ago [\#303193](#303193) by [scarney](/forum/user/31381-scarney "View scarney's Profile")  *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303193 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")* was created by *[scarney](/forum/user/31381-scarney "View scarney's Profile")*

-- url of the page with the problem -- : [ www.veggievore.com/dvd/why-we-do-what-we-do](https://www.veggievore.com/dvd/why-we-do-what-we-do)
-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9.2
-- Error-message(debug-mod must be tuned on) -- : General question. No error.

I wish to trigger a Google Analytics Event when someone select "Add to Cart". Is this possible? If so, how?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy84OTY3ODAtaS13aXNoLXRvLXRyaWdnZXItYS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXdoZW4tc29tZW9uZS1zZWxlY3QtYWRkLXRvLWNhcnQ/dG1wbD1tYXJrZG93bg==) 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: 14325
-
-

7 years 9 months ago [\#303216](#303216) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303216 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Hi,

It's possible yes.
You can use such javascript to plug yourself to the add to cart event and then trigger the GA event in your code. Code:

window.Oby.registerAjax('cart.updated', function(params) { console.log(params); // your code to trigger the GA event }

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

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

Less More

- Posts: 190
- Thank you received: 2
-
-

7 years 9 months ago -  7 years 9 months ago [\#303261](#303261) by [scarney](/forum/user/31381-scarney "View scarney's Profile")  Replied by *[scarney](/forum/user/31381-scarney "View scarney's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303261 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Thank you very much Nicolas,

I am wondering if we should be pasting this code into the file product / add_to_cart_ajax.php file for my template?
Also wondering if it matters where we put this code in that file. We have two pieces of code to add: Code:

// The code to record GA event (page view) for Hikashop pages with an add to cart button ga(‘send’, ‘event’, ‘Landing Page’, Page View); } // The code to record an event for every Hikashop Add to Cart click window.Oby.registerAjax('cart.updated', function(params) { console.log(“Add to Cart Event Occurred”); // your code to trigger the GA event ga(‘send’, ‘event’, ‘Landing Page’, ‘Add to Cart’); }

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

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy84OTY3ODAtaS13aXNoLXRvLXRyaWdnZXItYS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXdoZW4tc29tZW9uZS1zZWxlY3QtYWRkLXRvLWNhcnQ/dG1wbD1tYXJrZG93bg==) 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: 14325
-
-

7 years 9 months ago [\#303275](#303275) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303275 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Hi,

You need to add that javascript inside script tags either in the head or body of the pages where you have an add to cart button.
If you add it in add_to_cart_ajax, that will only do it for the products listings as that view file is not used on the product page.
You could add that code in your template. Or you could have a plugin to add that code to the header of the page. Or you could also add it in product/listing.php and product/show.php so that it is both on the listings and the product pages. All these are valid solutions. It depends what you prefer for the future maintainability of your code.

The following user(s) said Thank You: [scarney](/forum/user/31381-scarney "View scarney's Profile")

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

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

Less More

- Posts: 190
- Thank you received: 2
-
-

7 years 9 months ago -  7 years 9 months ago [\#303497](#303497) by [scarney](/forum/user/31381-scarney "View scarney's Profile")  Replied by *[scarney](/forum/user/31381-scarney "View scarney's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303497 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Thank you. I added the following code using loadposition to load a custom module created with Sourcer from RegularLabs tags but the event did not get picked up although the code is displaying in the source of the page. Do you have any idea why? The page is located at

[ www.veggievore.com/dvd/why-we-do-what-we-do](https://www.veggievore.com/dvd/why-we-do-what-we-do)

The code I added is
Code:

&lt;script&gt; // The code below will record a GA event for every Hikashop Product Page Page View console.log(“GA Page View”); ga(‘send’, ‘event’, ‘Landing Page’, ‘Page View’, window.location.pathname); } // The code below will record an event for every Hikashop Add to Cart interaction window.Oby.registerAjax('cart.updated', function(params) { console.log(“Add to Cart Event Occurred”); // your code to trigger the GA event ga(‘send’, ‘event’, ‘Landing Page’, ‘Add to Cart’, window.location.pathname); } &lt;/script&gt;

Last edit: 7 years 9 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: [code] tag is really nice

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

7 years 9 months ago [\#303504](#303504) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303504 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Hello,

Please use the [ code ] tag to paste some code.
It looks like there are some missing content ; I place the tag without touching the content, but we can see that there missing lines since there are missing open brackets or missing closing parenthesis.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

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

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

Less More

- Posts: 190
- Thank you received: 2
-
-

7 years 9 months ago [\#303829](#303829) by [scarney](/forum/user/31381-scarney "View scarney's Profile")  Replied by *[scarney](/forum/user/31381-scarney "View scarney's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303829 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Nicolas and Jerome,

I want to thank both of you for you help. We have been able to get working going being tracked and are grateful.

The GA code to record a GA Event when someone selects the Add to Cart button is working.

Can you please help us to know what is the code to record a GA Event when someone selects the Proceed to Checkout button?

You can see the working code, again, on this page:

[ www.veggievore.com/dvd/why-we-do-what-we-do](https://www.veggievore.com/dvd/why-we-do-what-we-do)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy84OTY3ODAtaS13aXNoLXRvLXRyaWdnZXItYS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXdoZW4tc29tZW9uZS1zZWxlY3QtYWRkLXRvLWNhcnQ/dG1wbD1tYXJrZG93bg==) 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: 14325
-
-

7 years 9 months ago [\#303835](#303835) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[I wish to trigger a Google Analytics Event when someone select "Add to Cart"](/forum/30-integrations/896780-i-wish-to-trigger-a-google-analytics-event-when-someone-select-add-to-cart#303835 "-- url of the page with the problem -- :   www.veggievore.com/dvd/why-we-do-what-we-do  -- HikaShop version -- : 4.0.1 -- Joomla version -- : 3.9.2 -- Error-message(debug-mod must be tuned on) -- : General question. No error.  I wish to trigger a Google Analytics Event when someone select &quot;Add to Cart&quot;. Is this possible? If so, how?")*

Hi,

There is no event being fired by HikaShop in such case.
so you'll have to plug yourself to the onclick of the button with your own javascript.
For example: Code:

var proceedButtons = document.getElementsByClassName("hikashop_cart_proceed_to_checkout"); var myFunction = function() { console.log('Proceed to checkout button clicked on'); return true; }; for (var i = 0; i &lt; proceedButtons.length; i++) { classname[i].addEventListener('click', myFunction, false); }

The same code can be used for any button on your website, provided that it has a specific class you can use to identify it.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMwLWludGVncmF0aW9ucy84OTY3ODAtaS13aXNoLXRvLXRyaWdnZXItYS1nb29nbGUtYW5hbHl0aWNzLWV2ZW50LXdoZW4tc29tZW9uZS1zZWxlY3QtYWRkLXRvLWNhcnQ/dG1wbD1tYXJrZG93bg==) 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.071 seconds

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