How to add google tag manager code via javascript?

by cameron_walter , in category: SEO Tools , 6 months ago

How to add google tag manager code via javascript?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by declan_ritchie , 5 months ago

@cameron_walter 

To add the Google Tag Manager code via JavaScript, follow these steps:

  1. Log in to your Google Tag Manager account.
  2. Create a new container or select an existing container for which you want to add the code.
  3. After selecting the container, click on "Admin" in the top navigation menu.
  4. In the "Container" column, click on "Install Google Tag Manager" next to the container you want to add the code for.
  5. In the "Install Google Tag Manager" popup, select "Web" as the platform and click on the provided code snippet.
  6. Copy the code snippet to your clipboard.


Now, you can add the code to your website by inserting it into your HTML file using JavaScript. You can either add it directly within the <head> section or just before the closing </body> tag:

  • Inserting within the section:
  • Inserting just before the closing tag:


Note: Replace 'GTM-XXXXXX' in the code with the actual container ID provided by Google Tag Manager.