How do I identify the store sending an AJAX request to my server using the script tag?

Shopify Partner
79 0 7

Hi

I am using the script tag API to install a JS file on a shop front end.

The js file sends an ajax request to my server when a form is submitted.

How do I identify the store that the request is coming from?

Thanks

Asa

Try the best recent order app for Shopify free for 7 days: https://apps.shopify.com/recently
0 Likes
Shopify Staff
Shopify Staff
582 0 45

Serve up "custom" javascript files per server or include a query parameter that you can use to identify the source.

0 Likes
Shopify Partner
79 0 7

Hi Chris

Thanks for the quick response.

"or include a query parameter that you can use to identify the source."

This is what I'm stuck with.

How can I send a parameter to identify the shop (source). I could probably get the domain name of the shop and check that against the shop in the local database in my app but what if the user is using a custom domain and I only have their *.myshopify.com domain in my db? Then it won't match.

Try the best recent order app for Shopify free for 7 days: https://apps.shopify.com/recently
0 Likes
Shopify Partner
79 0 7

Aha, I think I've just found the answer to my question by looking in the DOM tab in firebug.

There is a Shopify object that contains the shop name - which I guess should always match my database.

My only question on this subject now is... is this object in all themes or something that was added by theme developer in the theme I am using (launchpad)?

Try the best recent order app for Shopify free for 7 days: https://apps.shopify.com/recently
0 Likes
Highlighted
Shopify Staff
Shopify Staff
582 0 45

You are adding the scriptTag when the shop is installed. Generate a unique ID and set the script tag to that.

Otherwise set your script tag to be 

myserver.com/scripts/scriptname/unique_shop_identifier.js

 

0 Likes
Shopify Partner
79 0 7

Ah ok, I would need to set up some htaccess mod rewriting, unless I could do:

myserver.com/scripts/script.js?id=unique_shop_identifier ??

Is there any problem with my previous suggestion of getting the shop name from the Shopify object shop name?

Try the best recent order app for Shopify free for 7 days: https://apps.shopify.com/recently
0 Likes
Shopify Staff
Shopify Staff
582 0 45

It requires an extra request which isn't necessary.

I've done all this stuff with rails or sinatra routing so I've never had to deal with .htaccess. If you're doing PHP I guess that's what you'll have to do.

And actually, if you look at the script tag it will tell you which shop is requesting the JS. For example here's a request for some JS I needed for the now defunct Google Trusted Stores Shopify integration I worked on.

http://google-trusted-stores.shopifyapps.com/trustedstorebadge/b8051d87034f198a8662e84666de94f8.js?s...

 

0 Likes