Hi everyone,
I noticed that Shopify automatically injects the following script into my storefront pages:
<script type="text/javascript" async src="//[myshop].myshopify.com/cdn/s/trekkie.storefront....min.js"></script>
From what I understand, this is the Shopify Trekkie analytics script that powers Shopify’s analytics and tracking.
I want to run my own JavaScript before this Trekkie script executes — for example, to set up some global variables, handle cookie consent, or override tracking behavior.
However, since Shopify injects Trekkie automatically (not from theme code), I’m not sure where or how to safely run my script before Trekkie initializes.
Could someone clarify:
-
The best place in
theme.liquidto insert my custom JS so it runs first? -
Whether putting it before
{{ content_for_header }}ensures it runs before Trekkie? -
Any best practices for handling async timing or conflicts with Trekkie?
- Thanks in advance for any insights!