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:
-
- Log in to manage your site.
- Go to CAWeb Theme Options.
- Under the General Settings tab, expand the Google section.
- 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:
-
- From the template files, open and edit the /index.html file.
- Replace the default analytics ID with your agency ID:
- Google Analytics 4 (GA4): Replace G-75V2BNQ3DR on line 76 with your agency GA4 measurement ID
- 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:
-
- 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.
- Replace the default GA4 measurement ID with your agency ID:
- GA4: Replace G-75V2BNQ3DR with your agency measurement ID
- Save changes and push to production per your department standards.
JavaScript code
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:'samesite=lax;domain=.'+document.domain}); // statewide GA4 measurement ID gtag('config', 'G-75V2BNQ3DR', {cookie_flags:'samesite=lax;domain=.'+document.domain}); // individual agency GA4 measurement ID </script>
Universal Analytics
<!-- Universal Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-20973992-30"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); //statewide GA property gtag('config', 'UA-3419582-2'); //please update state department UA code in line below before deployment gtag('config', 'UA-20973992-30'); var getOutboundLink = function(url) { gtag('event', 'click', { 'event_category': 'navigation', 'event_label': 'outbound link: ' + url, 'transport_type': 'beacon', 'event_callback': function(){document.location = url;} }); } var trackDownload = function(filename) { gtag('event', 'click', { 'event_category': 'download', 'event_label': 'file: ' + filename, 'transport_type': 'beacon', 'event_callback': function(){document.location = url;} }); } </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:
-
- Going to Reports > Realtime and confirming pages you are actively visiting show up under Views by Page title and screen name.
- Waiting 24 hours for analytics to display in your Google Analytics Reports dashboard under Life cycle > Engagement > Pages and screens.