skip to Main Content

I work with some third party referral systems and I’ve been looking for a way to trigger some JS off of events like Add To Cart, Add Coupon to Order, and Checkout. I’d like to be able to do this without having to use the id of the button in question as these can change from theme to theme, and become complicated when you’re dealing with multiple buttons for the same functionality.

It seems like the built in Google Analytics and Facebook Tracking are using some sort of event system to trigger their data collection, but I can’t seem to find anything in the docs or forums explaining how this works or how I can use it without using their services. Ideally I’m looking for some kind of liquid if/then sort of structure or alternatively just a clear event of some kind that I can listen for.

Obviously I could use jquery to accomplish this by listening for different button clicks but that seems like a really brittle way of handling something that is clearly part of the core of how Shopify works.

Any thoughts or suggestions would be really appreciated (At this point I’ll name my first born rumplestiltskin)

(Repost from here https://ecommerce.shopify.com/users/554977/posts)

2

Answers


  1. Do what everyone does, including GA and other trackers. Build an App that installs in shops, and that App uses the API to inject JS that triggers onload. You can then program the JS to callback your mothership with the data you are interested in.

    Note that your approach of asking for a trigger is far too vague to ever work. Why re-invent the wheel or beat a dead horse. Free up your valuable time and just go with the flow.

    https://help.shopify.com/api/reference/scripttag

    Login or Signup to reply.
  2. You can subscribe to webhook events through the API:
    https://help.shopify.com/api/reference/webhook

    There are topics for carts/create and checkouts/create which you might find useful. For coupon codes, you can subscribe to orders/create webhooks and parse the order data to see if it contains a coupon code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search