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 Options and select Settings.
    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. This update will restrict the GA4 measurement ID to the specific domain and it will no longer travel across ca.gov sites.

To learn more, visit the Security section on our Help with analytics page. 

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. Our team is currently unable to assist with the configuration of GTM containers. We can, however, create and manage your GTM account.

If you’d like to use GTM to add your Google Analytics ID to your site, submit a request to our CAWeb Team using our Google Search and Analytics Request through ServiceNow to request a GTM account. This will ensure the long-term availability to this important resource in the event of State agency staff turnover. 

To learn more about GTM, visit our Use Google Tag Manager to Add Google Analytics page.

Confirm you’re collecting data

Once your GA4 measurement ID is in production, you will need to confirm your analytics account is collecting data.

Install Chrome Debug extension

If this is the first time you are checking to confirm your analytics account is collecting, you will need to: 

  1. Open Google Chrome browser. 
  2. Install Debugger for Google Analytics 4 (GA4) browser extension. 
  3. Once installed, turn the extension on in your browser. 
Check using Debug view

If you already have the Debugger for GA4 browser extension installed, you are ready to test that your analytics is set up properly.

To confirm your account is collecting data using Google Chrome: 

  1. Open Google Chrome browser. 
  2. Log in to your Google Analytics account.
  3. Go to the Admin settings and expand Property settings.
  4. Expand the Data display section and select Debug view. The Debug window should show: “Waiting for debug events.” Do not click in the panel – clicking the middle panel will pause the debug view window. To unpause, you will need to click again. Leave this browser tab/window open. 
  5. Open a new browser tab/window and navigate to the site you’ve added your GA4 measurement ID to. 
  6. Once on your site, make sure the GA Debugger extension is set to “ON.” 
  7. Click around your site – be sure to click on links that navigate through your site and not to other sites.
  8. Once you’ve clicked around, return to your Analytics Admin Settings – Debug view tab/window. 
  9. If the Debug window shows:
    1. A timestamp with events – Your GA4 measurement ID is installed correctly and is collecting analytics for your site. 
    2. Waiting for debug events (and the window isn’t paused) – Your GA4 measurement ID is not installed correctly and it is not collecting analytics for your site. Double check your code to confirm you’ve added it properly. If you continue to have issues, contact our CAWeb Team using our Google Search and Analytics Request through ServiceNow.