Jan Żankowski
Jan Żankowski

Reputation: 8941

How do I write a Shopify app which adds some Javascript to all shop pages (via ScriptTag)?

I'm looking for a minimal set of directions that allow me to do this. Unfortunately, Shopify app documentation is not great.

Upvotes: 0

Views: 113

Answers (1)

Josh Brown
Josh Brown

Reputation: 4096

You can create a ScriptTag by making a POST request to the /admin/script_tags.json endpoint. Your app would need the write_script_tags scope. Here is an example using curl:

curl -H "Content-Type: application/json" -H "X-Shopify-Access-Token: youraccesstokengoeshere" -X POST "https://yourstore.myshopify.com/admin/script_tags.json" -d '{
  "script_tag": {
    "event": "onload",
    "src": "https://yoursite.com/yourscript.js"
  }
}'

https://docs.shopify.com/api/uiintegrations/scripttag#create

Upvotes: 3

Related Questions