Load script on page before onLoad using scriptTag

Hello there!

There are a few ways to insert a script directly into a Shopify theme or use the DOMContentLoaded event for the scriptTag:

  1. Using the Shopify theme editor: You can use the Shopify theme editor to add a script directly to the theme. You can access the theme editor by navigating to the “Online store” section of your Shopify admin panel and then clicking on “Themes”. Once you have selected your theme, you can click on the “Actions” button and select “Edit code”. From here, you can add your script to the appropriate file, such as the theme.liquid file for a global script or a specific page file for page-specific scripts.
  2. Using the Shopify ScriptTag API: You can use the Shopify ScriptTag API to add a script to your store. The ScriptTag API allows you to create, read, update, and delete script tags. You can use the ScriptTag API to add your script to the store and set the event to DOMContentLoaded. Once the DOMContentLoaded event is fired, your script will be executed.
  3. Using a Shopify app: You can use a Shopify app to insert your script directly into the theme. There are many apps available that allow you to add custom code to your store, such as “Code Injector” or “Custom Code”. These apps allow you to add your script directly to the theme and set the event to DOMContentLoaded.
  4. Using a Custom Theme Section: You can create a custom theme section, in this section you can add an html script tag, then you can add the section to any page you want. This way you can have the script where you need it and avoid adding it to all pages.
  5. Using a Shopify theme section feature: Some premium themes come with built-in sections that allow you to add custom code. You can use this feature to insert your script directly into the theme and set the event to DOMContentLoaded.

hope this helps!