Workflow Help needed

Shopify Partner
46 0 4

I am creating a widget for all the Shopify sites which uses Facebook for cart abandon etc. The widget is something like the Shopmessage. Digging through the docs of Shopify I created a basic workflow using 2 types. Please point out if there are any mistakes in my understanding.


Type 1,


  • Create a script (which loads my widget using scriptTags API)
  • Using the script injects the widget to the store.
  • Since the script won't have access to the liquid variables such as customer, cart, products, etc, create a unique userId to the user. Each time the user subscribes to the widget send along the userId (voila!!! we have a subscriber).
  • To know the status of the cart and to send cart abandon messages, use AJAX API of the Shopify. Periodically call cart.js and know the cart details. Also, use ShopifyAnalytics object or parse the URL to get product info and use Shopify.getProducts for fetching products. I have tried using Shopify.onItemAdded and Shopify.onCartUpdate but no use. Nothing happens.
  • Also, I want my widget to appear in some certain URL. So all I can do is parse the URL and check each time to determine show or not show. 

Type 2,


  • Create a snippet using asset API. Which includes a div tag for injecting and add to theme.liquid file. Use script tags API to add a script which injects into this div my widget.
  • Using another snippet which will be added to products.liquid expose customer details and product info to a global variable. (This is pretty weird).
  • Follow the steps of Step 1 to identify the subscriber (now I have customer details if logged in).

Any help appreciated. Which methods are you guys suggest? Are there any good methods to address my scenario? Any help appreciated



Shopify Partner
2576 134 438

That's a long one.


TYPE 1 - Where/how is your widget being injected? Does the merchant need to add a DOM hook?


userId - eventually you may want a heuristic combining several metrics to make a fingerprint to increase the confiden that id's are unique (account for things like multiple tabs, browser private mode)


"Shopify.onItemAdded and Shopify.onCartUpdate" et. al don't assume the existence of other javascript either common shopify js or libraries like jquery


product info is "/product handle".json


Type 2 - If your adding a snippet why not load your script there? Or are you trying to take advantage of scripttags load process?

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ or donate to
Confused? Busy? Buy a custom solution
Shopify Partner
46 0 4
Type 2 has issues modifying the templates etc. Which is burden. Using
scripttags we can support custom themes also. IAM very new to Shopify
development. Any help would be appreciated. Also if you have any prior
experience creating such widget please do share. I want to track when the
customer add product etc. Any solution for this ? IAM creating widget like
shopmessage and privy. (Based on Facebook)