How can users selectively embed a script per page on my app?

I need a way for users of my Shopify app to selectively add a script tag to their pages. It is up to the user to decide if they want the script’s behavior per page.

The way we advise users to do this currently is to walk them through creating a theme snippet and adding the snippet render code to the pages they want it on. This works, but is somewhat technical and not very user-friendly. I’ve been trying to see if there is a better way to automate this with the Shopify app API.

The ScriptTag API seems to only let you choose if the script is added to the storefront or order status pages via the display_scope property.

App embed blocks seemed very promising. The docs even say “App embed blocks allow you to only load scripts on specific pages”. But when I tried to test this approach in code, it seems less flexible. It seems like you can only specify which pages the embed block is available on with the ‘template’ schema attribute. But for those selected pages the embed block is toggled off or on for ALL of those pages. The users can’t selectively turn the embed block off or on per page.

Is this correct, or am I misunderstanding some details of app embed blocks?

Based on all of that, is the best approach still to have users create theme snippets? Or does anyone have suggestions of another approach to automate this and make it easier for end users?

1 Like