Google Analytics – Statewide Analytics Code Setup

Before you set up the Google Analytics statewide code on your website, you will need a Google Analytics Universal Analytics (UA) code to start collecting analytics. If you don’t already have a UA code, you will need to submit a Google Search and Analytics request to the CA Web Team through ServiceNow.

Once you have a UA code, you can set up your statewide analytics one of two ways:

    • Using the state template
    • Using your own custom template

State template setup

If you are using the state template for your website, the statewide analytics code is already part of the state template.

Once you have a UA code for your website, follow these steps to start collecting analytics:

    1. From the template files, open /js/search.js.
    2. Replace the existing UA-20973992-30 code with the UA code for your website.
    3. Save changes and push to production per your department standards.
    4. From the template files, open /ssi/analytics.html.
    5. Replace the existing UA-20973992-30 code with the UA code for your website.
    6. Save changes and push to production per your department standards.

Once you save and push the changes to production, it may take up to 24 hours for analytics to display in your Google Analytics dashboard.

Custom template setup

If you are using your own custom template, you will need to copy the code below to implement statewide analytics on your website.

Once you have a UA ID for your website, follow these steps to start collecting analytics:

    1. Copy and paste the 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 existing UA-20973992-30 code with the UA code for your website.
    3. Save changes and push to production per your department standards.

Once you save and the push the changes to production, it may take up to 24 hours for analytics to display in your Google Analytics dashboard.

Code

<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>