Take the 2-minute tour ×

I am developing an analytics product similar to Google Analytics and want to offer an integration for our Shopify users.

I would need to do just two things:

1) Insert our JavaScript snippet into the body of all the shop's pages

2) Insert a second conversion snippet into the body of only the "thank you" page after a purchase to record the sale, passing back the order total and order number

Could you point me in the right direction?

The ScriptTag endpoint looks optimal except that it doesn't seem to provide any way to differentiate between the "thank you" page and other pages, or to pass the order details from the "thank you" page into the script.

It seems like I either need an endpoint that can inject arbitrary code into all pages, or one which lets me alter the theme layout file to add code before the </body> tag.

If I can do that much, it looks like I might be able to use a conditional in the templating language to only show the conversion code if the URL matches the "thank you" page URL, and use {{ total_price }} and {{ order_number }} in that code.

Does the uninstall webhook allow me to make changes before the rights for the app are revoked? It seems like I would need a way to clean up at uninstall to remove my code from the theme, if I'm allowed to edit the layout file.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

itThere are two ways you can go about this:

ScriptTags: You're already aware of this method. It's true that the script is loaded into each and every page, but you can look at document.url in your js to figure out which page you're on and conditionally execute code based on that.

Scripts inserted this way are executed during the 'onLoad' event. At that time you have access to the DOM and can do basically whatever you want with the page.

Snippets: Using the Assets endpoint you can make arbitrary changes to the user's theme. Be careful with this power! The recommended way to make complex changes to a page is to create a custom snippet in the theme with your additions and then tell the user to insert an include tag into their code where it needs to appear. This reduces clutter in the main theme files.

I'd recommend using ScriptTags wherever possible. As mentioned below, they don't need cleaning up and remove the need for user interaction when setting up the app.


As for the uninstall webhook: It is fired after the app has been uninstalled from the shop, so you no longer have access. It's designed to be used to trigger cleanup on your end (remove db entries, etc.). Note that ScriptTags and Webhook subscriptions are automatically cleaned up, but any changes you've made to the theme aren't

share|improve this answer
The Thank You page markup is fixed, and not part of the shop's regular theme. This means scraping it isn't too bad. Another way is to get the merchant to paste some code into the 'additional content and scripts' box of their admin, where you have liquid access to the order. Not ideal, I'll admit, but definitely workable. –  David Underwood Aug 30 '12 at 18:16
Thanks, will be setting up an app in the next few days to see if we can write a custom script to inject and scrape the info from a thank-you page. –  Dan Grossman Aug 31 '12 at 7:01

You ask a lot of questions in one posting.

For your #1 and #2 read:


Secondly, for your app install/uninstall read:


Pay attention to the part about app/uninstalled since you're interested in that.

As for knowing when someone installs your App, that is really up to you to figure out. Should not be too hard since you probably read about how to make and App in the first place. Shopify provides lots of boiler plate code on github that can show you almost everything you asked here.

share|improve this answer
Shopify told me to post it here, that the Shopify developers would answer it here. The ScriptTag endpoint doesn't seem to allow you to insert your own JavaScript, only the URLs to external scripts. It also wouldn't be possible to capture things like the order number and order total by just inserting a generic URL into a script tag in all pages. I don't think this will accomplish either of my goals. –  Dan Grossman Aug 29 '12 at 23:44
If you don't like that, then you can always download the merchants theme.liquid, and place your own script in it. This sucks since the merchant is then at your mercy... but some will accept that. Plus when they uninstall your App, that kind of stuff is NOT cleaned up. Since you have access to the order number and total in the Thank You script, you simply need to get them to paste a snippet of code for you in the their shop for that purpose. In other words, your needs are easily met as long as the merchant does some of the work for you. –  David Lazar Aug 30 '12 at 1:04
Well, that's why I asked what the endpoint was to get the theme.liquid file, what the liquid variables for the order info are, and how I can clean up on uninstall. I hope a Shopify developer can answer this eventually. Today I can give users instructions to insert the code themselves; the purpose of this question is to determine how I can provide a Shopify app that does it for them. –  Dan Grossman Aug 30 '12 at 1:06

Your Answer


