Forum Discussion

Will_Findlay's avatar
Will_Findlay
Community Member
22 days ago

Can I insert Google Analytics javascript in a trigger?

Will it work to put the code below in a trigger: "Execute JavaScript when the timeline starts on this slide?" I want to track using Google Analytics, but I don't want to edit the HTML launch file eve...
  • Will_Findlay's avatar
    Will_Findlay
    22 days ago

    Can confirm that this works!

    1. Set up your Google Analytics property
    2. In Google Analytics go to Admin (gear icon) > Data collection and modification > Data streams
    3. Add a stream if needed
    4. Click on the stream and click "View tag instructions."
    5. Choose "Install manually."
    6. Copy the code it gives you and paste into a text editor
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-YOURGCODE"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'G-YOURGCODE');
    </script>

    7. Replace lines 2 and 3 with the actual javascript contents of the page at https://www.googletagmanager.com/gtag/js?id=G-YOURGCODE

    8. Copy all of that and paste into a Javascript Trigger.