OneTrust script executing after Google Tag Manager

1.6k Views Asked by At

I'm trying to reorder the execution of scripts in my codebase. What I need is for the OneTrust scripts to fire before my GTM scripts and for whatever reason I can't seem to get that to happen.

I've tried:

  1. Reordering the scripts in the head
  2. Using j.async and j.defer in the GTM script
  3. Using the addEventListener method to attach a load event listener to the OneTrust script, and then include the Google Tag Manager script inside the event listener function.
document.addEventListener('DOMContentLoaded', function() {
    var gtmScript = document.createElement('script');
    gtmScript.src = 'googletagmanager.js';
    document.body.appendChild(gtmScript);
  });
0

There are 0 best solutions below