App is currently using ScriptTag API - considering 2 options for updating for theme 2.0

App is currently using ScriptTag API - considering 2 options for updating for theme 2.0

Brett_Bernstein
Shopify Partner
11 0 0

Hi Developer support, we are running into an issue updating our script for 2.0 themes, hoping you can help us out.

 
This is our script that gets added when the app is installed:
https://gatsby-statics.gatsby.tech/$brandslug/script.min.js

The $brandslug is unique per brand / merchant.
 
In the 2.0 theme extension, we are not able to find the merchant's name as the same code is global for all merchants, so we are unable to populate that variable in the script.
 
Do you know how other apps are solving for this?
 
We're considering two solutions:
 
Solution 1:
1. Detect the online store theme type. If the active theme is not 2.0, then we continue using the Script Tag API to add our custom script into online store as a theme app extension for the application.
2. With the theme app extension, we are adding the app block including the custom script for 2.0 stores.
3. For 2.0 stores, the merchant needs to enable the "App Block" in the theme settings.
 
Solution 2:
Remove the unique brand slug and give the same script to every merchant and figure out another place or way to add a unique variable for the merchant's specific Gatsby account later.
 
I feel like solution 2 is better long term, but keen to hear any suggestions or what other app developers are doing for best practice. Thanks!
 
Brett Bernstein - Founder & Gatsby - gatsby.ai
Replies 2 (2)

globosoftware
Shopify Partner
19 2 7

I recommend you should use App Embed block. It could work for both classic theme & 2.0 theme. 

 

Click to expand...
This is our script that gets added when the app is installed:

The $brandslug is unique per brand / merchant.

When you change to theme app extension, the script will be same for all merchants. so, we need add shop data to metafield. then using metafield as variants in script file. 

Brett_Bernstein
Shopify Partner
11 0 0

Thank you! Looking into your suggestion

Brett Bernstein - Founder & Gatsby - gatsby.ai