hero

How to add the script to your site using Google Tag Manager

You can use Google Tag Manager (GTM) to add Beam Analytics tracking code to your website. There are a few steps to get it to work.

1. Add a new tag

In your GTM account, go to the ‘Tags’ tab and click on ‘New’.

2. Begin tag type setup

Click on the ‘Tag Configuration’ box so you can choose a tag type to begin setup

3. Select 'Custom HTML'

Scroll down and find Custom HTML. It should be in the Custom section which is the second section from the top.

4. Paste this Beam code

<script>
  var script = document.createElement('script');
  script.defer = true;
  script.dataset.token = "YOUR_BEAM_TOKEN";
  script.dataset.api = "https://api.beamanalytics.io/api/log";
  script.src = "https://beamanalytics.b-cdn.net/beam.min.js";
  document.getElementsByTagName('head')[0].appendChild(script);
</script>

What does this code do?

This code will generate your Beam snippet, and add it to the section of the page. Make sure to change YOUR_BEAM_TOKEN to your actual token! Note that if you are using other features such as tag firing priority, tag sequencing, consent checks, they all may affect when and how Beam’s script loads.

5. Choose a trigger to make this tag fire

Under where you pasted the Beam code, click on the ‘Triggering’ box.

6. Select ‘All Pages’

7. Name your tag

Here, we use ‘Beam Analytics’.

8. Save, submit, publish

In the top right hand corner of the next three screens click on:

  • Save
  • Submit
  • Publish

You’re done! To verify, go to your

a. website and verify whether the Beam script has been added

b. Beam account to see whether your stats are being tracked

Track custom events using Google Tag Manager

To track custom events, you just need to change the default tracking script to add the tagged-events extension. And if required, add the extra script to trigger the custom event.

Debugging using Google Tag Manager and Beam

  • If things aren’t working, check the consent area of GTM. You might need to give consent to allow our script to fire.
  • GTM is blocked by Firefox, Brave and Safari. It is also blocked by many browser extensions. This means that the Beam script you're using with GTM will be blocked too by a certain percentage of your visitors. Using Beam without GTM will mean it’s blocked by fewer people and your data will be more accurate.

If you have any questions or issues, please email us at hi@beamanalytics.io!

Ready to dive in?
Start your free trial today.