vemund
vemund

Reputation: 1817

Google Analytics Event tracking code issue in Shopify?

Trying to build a better tracking than the eCommerce tracking that is set up for Google Analytics and Shopify.

On my frontpage, I have a list of bestsellers. These products can be added to cart, but this is done with an ajax, and you are not redirected to the cart once a product is added. I tried to track this event by using Google Analytics Goal Events. Below is the add product to cart form:

<form method="post" action="/cart/add">
          <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
          <input type="submit"  value="<ly-as-2156597>Add To Bag  |</ly-as-2156597>  {{ product.price | money }} " class="submit add hidden-phone"  onClick=”_gaq.push(['_trackEvent', 'bestseller', 'click', '{{ product.title }}', '{{ product.price | money_without_currency }}']);” />
        <a href="{{ product.url | within: collection }}"><input style="
    width: 60px !important;" type="button" value="<ly-as-2156598>View</ly-as-2156598>" class="submit" /></a>
        </form> 

As you can see, the _trackEvent is added, and it is also added in Google Analytics Goals.

When I test this however, it does not appear in the Real-Time views, so it is not working.

Any ideas?

Upvotes: 0

Views: 1535

Answers (2)

vemund
vemund

Reputation: 1817

I fixed this by using this code:

onClick="ga('send', 'event', 'Bestsellers', 'Added to Cart', '{{ product.title }}', '{{ product.price | money_without_currency }}');"

Upvotes: 0

Vinnie James
Vinnie James

Reputation: 6062

The _gaq method is a legacy call to ga.js https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gaq

You probably need the new syntax for analytics.js, something like this: ga("send",{hitType:"event",eventCategory:"click",eventAction:"bestseller",eventLabel:product.title}) https://developers.google.com/analytics/devguides/collection/analyticsjs/events#overview

Upvotes: 2

Related Questions