Forum Discussion
Can I insert Google Analytics javascript in a trigger?
- 4 months ago
Can confirm that this works!
- Set up your Google Analytics property
- In Google Analytics go to Admin (gear icon) > Data collection and modification > Data streams
- Add a stream if needed
- Click on the stream and click "View tag instructions."
- Choose "Install manually."
- 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.
So, I'm attempting a workaround: I'm going to https://www.googletagmanager.com/gtag/js?id=G-MYGCODE (replacing MYGCODE with my actually Google Analytics code) and then copying and pasting everything into the trigger above the original script so it doesn't need that line 1 that is <script async="" src="https://www.googletagmanager.com/gtag/js?id=G-MYGCODE"></script>
Can confirm that this works!
- Set up your Google Analytics property
- In Google Analytics go to Admin (gear icon) > Data collection and modification > Data streams
- Add a stream if needed
- Click on the stream and click "View tag instructions."
- Choose "Install manually."
- 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.