Open cfxd opened 4 years ago
Not sure if this is helpful but we recently moved all of our third-party scripts on sites to Google Tag Manager which gives you and the client a central place to manage everything without needing to re-deploy the theme. You can also specify when and how to invoke the scripts which keep things performant.
It's helpful yet also poses more questions. How are you integrating GTM?
@cfxd This does not have anything to do with Slate, and it's more of a general Shopify development question. The Shopify Community is a great place to ask questions like this. https://community.shopify.com/c/Shopify-Community/ct-p/en
Although I will say that this is by far the best guide I have found to integrate GTM for shops that are not Shopify Plus accounts. https://www.getelevar.com/how-to/google-tag-manager-shopify/
@jonathanmoore thank you for the link. I do think it has something to do with Slate since I'm asking about best practices. If I wasn't working with Slate then I could just, as most third party integration guides suggest, paste that code right before </body>
, but then I lose async and ideally I'd like not to.
@cfxd I would second the use of GTM for this scenario. I definitely can relate to the pain of having to keep up with all the 3rd party scripts, and while dropping them in theme.liquid
with async/defer does work it just doesn't feel great. I think you'll be hard pressed to find a theme based solution that doesn't create the developer overhead you mentioned because as soon as those scripts hit the theme files they're part of the build/git/backup process.
With GTM containers though you can really fine tune script behavior, add triggers, specific page loading, etc. The one drawback that immediately comes to mind here is that you lose Liquid templating with the scripts by removing them from your theme. However you could easily add just about any variable to your data layer with JS and use them in GTM however you need.
Problem
Best practices are unclear for installing the many third party tracking apps offered by Shopify vendors. These scripts are similar to Google Analytics where a
<script>
tag links to an external third party single JS file, and a subsequent block of code then invokes a function, method, or object/class/variable from the JS file.Saving these single JS files locally seems rather tedious and then charges developers with keeping the vendor file updated, and just adding them to a template/section/snippet could end up render blocking.
One example is Klaviyo's back in stock flow snippet: