C15T Logo

Google Tag (gtag.js)

Learn how to use Google Tag (gtag.js) with c15t.

tocOn this page

Canary Feature

This feature is available in canary releases and may have breaking changes. Use with caution in production. Report issues on GitHub

Google Tag (gtag.js) is used to send data to various Google products like Analytics, Ads & Floodlight. Based on the product you are using you should set the category to marketing (Ads & Floodlight) or measurement (Analytics).

By default, c15t will always load this script regardless of consent. This is because Google Tag manages its own consent state via Google Consent Mode v2.

c15t will automatically sync the consent state so you don't need to do anything extra.

Implementation

Adding the script to c15t

import { configureConsentManager } from 'c15t';
import { gtag } from '@c15t/scripts/google-tag';

configureConsentManager({
  // ... 
  scripts: [
    gtag({
      id: 'G-XXXXXXXXXX',
      category: 'marketing',
    }),
  ],
});

Types

GtagOptions

Property
Types

Script

Property
Types