How can I identify the shop executing my js file on my server?

Shopify Partner
10 0 0

Hello, 

I'm trying to use script tags. I've created a file called store.js in my server. When I enter to my store I can see that the file is there and everything it's ok. The question is : How can I know the shop url (shopname.myshopify.com) that executed my file? I saw another post about this but I didn't understand it. It says to create a js file with an identifier. I'm not sure I understand how to do such thing. 

If you can show  me a clear example it would be great. BTW I use PHP, Jquery & Ajax.

Thanks!

0 Likes
Highlighted
Shopify Partner
10 0 0

Boom! I did it and here is the simple answer for all people looking for a solution with php.

I checked my html source on my shop and shopify added this to my js file first time I tried with a js file :

url/script.js?shop=myshop.myshopify.com 

So I thought about it and in the json string, I send a php file instead a js file like this :

array('event'      => 'onload','src'    => 'https://myserver.com/scripts/script.php'); 

Since php files can receive parameters, I just receive the parameter with the GET method :

 $shop =  $_GET['shop'];

I hope it helps ;)

0 Likes