Add analytics to your site

In order for your analytics account to collect data, our analytics JavaScript with your analytics GA4 measurement ID needs to be on every page of your website. How you apply our analytics JavaScript to your entire site will depend on if your website is managed by:

    • Our CAWeb Team
    • Your agency

CAWeb managed websites

If our CAWeb Team manages your website, we will add your GA4 measurement ID to every page of your site. We will also confirm that your analytics account is collecting data.

To confirm your GA4 measurement ID is applied to your site:

    1. Log in to manage your site.
    2. Go to CAWeb Theme Options.
    3. Under the General Settings tab, expand the Google section.
    4. There should be an ID in the Analytics ID and Analytics 4 ID fields.

Agency managed websites

If you are an agency managing your own site, you will need to add our analytics JavaScript to every page of your website. Our CAWeb Team will provide you with your agency GA4 measurement ID to include in our analytics JavaScript – this will ensure data is collected into your analytics account.

California State Web Template setup

If your agency is using the most recent version of our California State Web Template, our analytics JavaScript is already part of your files. To collect analytics to your account, you will need to:

    1. From the template files, open and edit the /index.html file.
    2. Replace the default analytics ID with your agency ID:
      1. Google Analytics 4 (GA4): Replace G-75V2BNQ3DR on line 76 with your agency GA4 measurement ID
    3. Save changes and push to production per your department standards.

Custom template setup

If you are using your own custom template, you will need to add our JavaScript into the <head> tag section of every page on your website. To collect analytics to your account, you will need to:

    1. Copy and paste the JavaScript code below into the <head> tag section of every page on your website. We recommend you paste it in right before the closing </head> tag.
    2. Replace the default GA4 measurement ID with your agency ID:
      1. GA4: Replace G-75V2BNQ3DR with your agency measurement ID
    3. Save changes and push to production per your department standards.

JavaScript code

Internet cookies

We’ve updated our JavaScript code to address security guidance for:

  • Secure flag
  • SameSite attribute
  • Cookie domain

This update will restrict the GA4 measurement ID to the specific domain and it will no longer travel across ca.gov sites.

Google Analytics 4
<!--Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-75V2BNQ3DR"></script> 
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());

            gtag('config', 'G-69TD0KNT0F', {cookie_flags:'secure;samesite=lax;domain='}); // statewide GA4 measurement ID
            gtag('config', 'G-75V2BNQ3DR', {cookie_flags:'secure;samesite=lax;domain='}); // individual agency GA4 measurement ID
        </script>

Contact our CAWeb Team through ServiceNow if you have any issues implementing the new code.

Google Tag Manager

Some agencies prefer to leverage Google Tag Manager (GTM) to add their Google Analytics ID onto their website. If you’d like to use GTM to add your Google Analytics ID to your site, visit our Use Google Tag Manager to Add Google Analytics page.

Confirm you’re collecting data

Once your analytics ID is in production, you will need to confirm your analytics account is collecting data. Log in to your Google Analytics account, and then confirm your account is collecting data by either:

    1. Going to Reports > Realtime and confirming pages you are actively visiting show up under Views by Page title and screen name.
    2.  Waiting 24 hours for analytics to display in your Google Analytics Reports dashboard under Life cycle > Engagement > Pages and screens.