8.3.3 Connecting Google Analytics to your site
Google Analytics is a free service from Google that allows you to track and analyze your website’s traffic. With it, you can get detailed information about who visits your site, how they do it, and what they do on it. This data helps you make informed decisions about optimizing your site and marketing campaigns.
Information: Google Analytics 4 (GA4) is the current version of the service, which has replaced Universal Analytics (UA). As of July 1, 2023, Universal Analytics stopped collecting data, so in this article, we will only cover connecting and using GA4.
Registration and Creating a Google Analytics Account
Before connecting Google Analytics to your website, you need to create an account and set up a property for tracking.
-
Go to the official Google Analytics website and sign in using your Google account.
-
Click the Start measuring button.
-
Specify the account name (usually the name of your company or organization).
-
Configure the data property:
- Enter the **property name** (usually the name of your website).
- Select the **time zone** and **currency** that will be used for reports.
- Click **Next**.
-
Provide information about your business or organization and click Create.
-
Accept the terms of service.
Connecting Google Analytics to Your Website
After creating an account and property, you need to connect your website to Google Analytics. There are several ways to do this:
Method 1: Using the Google Analytics Tag (Recommended Method)
-
In the Google Analytics dashboard, go to the Admin section.
-
In the Property column, select Data Streams.
-
Click on Add Stream and select Web.
- Enter your website URL and the data stream name, then click Create stream.
- After creating the data stream, you will see a Measurement ID that starts with “G-”.
- Click on Tag Setup Instructions and copy the suggested code, which will look something like this:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
- Insert this code in the
<head>
section on all pages of your website. If you’re using a CMS, this can be done through theme settings or with special plugins.
Warning: Replace G-XXXXXXXXXX with your actual Measurement ID received from Google Analytics.
Method 2: Using Google Tag Manager
For more flexible tag management and tracking of various events, it’s recommended to use Google Tag Manager (GTM).
-
Create an account in Google Tag Manager.
-
Create a container for your website.
-
In the GTM interface, create a new tag:
- Select the tag type **Google Analytics: GA4 Configuration**.
- Enter your **Measurement ID** (G-XXXXXXXXXX).
- Set the trigger to **All Pages**.
- Save and publish the changes.
- Install the GTM code on your website, following the instructions.
Tip: Google Tag Manager allows you to add and modify tags without having to edit the website code, which is especially convenient for marketers and analysts who don’t have access to the site’s source code.
Verifying Correct Installation
After installing the tracking code, it’s important to ensure that data is being collected correctly:
-
Install the Google Analytics Debugger browser extension.
-
Enable it and visit your website.
-
Open the developer console in your browser (F12) and check that requests to Google Analytics are being sent without errors.
-
In the Google Analytics interface, go to Reports > Realtime and make sure your visit is displayed.
Information: After the initial setup of Google Analytics, it may take up to 24 hours for the service to start fully collecting and displaying data in reports.
Key Google Analytics Metrics
After successful connection, you will have access to many useful metrics. Here are some of the most important ones:
Audience Metrics
Help you understand who visits your website: where they come from, how often they return, which devices they use, their age, gender, and interests. These core metrics are crucial for building an effective marketing strategy.
- Active Users – the number of unique visitors to your site during the selected period.
- New and Returning Users – the ratio of new to repeat visitors.
- Demographic Data – age, gender, and interests of visitors.
- Geographic Distribution – countries and cities from which users come.
- Devices and Browsers – what devices and browsers are used to access your site.
Engagement Metrics
Measure how users interact with your site. These metrics reveal how interesting and usable your content is and highlight areas for UX improvement.
- Engagement Rate – the percentage of sessions that were engaged (viewing multiple pages or performing conversion actions).
- Pages per Session – the average number of pages viewed during a single session.
- Average Session Duration – how much time, on average, a user spends on your site.
- Bounce Rate – the percentage of users who left the site after viewing only one page.
Traffic Source Metrics
Show where your traffic is coming from, helping you analyze the effectiveness of SEO, ads, social media, and referral channels.
- Channels – where traffic comes from (organic search, direct, referral, social, etc.).
- Source/Medium – detailed information about specific traffic sources.
- Campaigns – effectiveness of marketing campaigns when using UTM tags.
Conversion Metrics
Track how well your website achieves its business goals. They help identify the steps users take from entering your site to completing key actions.
- Events – user actions on the site (clicks, downloads, form completions, etc.).
- Conversions – achievement of goals that you’ve defined as important for your business.
- Conversion Funnels – the user’s path from entering the site to completing a target action.
Setting Up Goals and Events
For more effective tracking of user actions, set up events and conversions:
Setting Up Events
-
In Google Analytics 4, go to Admin > Property > Events.
-
You can use automatically tracked events or create your own.
-
To track specific actions, you need to add the corresponding code to the site:
gtag('event', 'event_name', {
'parameter1': 'value1',
'parameter2': 'value2'
});
For example, to track clicks on the “Order” button:
document.querySelector('#order-button').addEventListener('click', function() {
gtag('event', 'button_click', {
'button_name': 'order',
'page_location': window.location.href
});
});
Tip: Remember that data collection is only the first step. It’s important to regularly analyze the information obtained and take specific actions based on it to improve your site and marketing strategies.
Setting Up Conversions
-
Go to Admin > Property > Conversions.
-
Click the New conversion button.
-
Select the event you want to mark as a conversion and click Save.
Tip: It’s recommended to set up conversions for key actions on the site, such as completing an order, submitting a contact form, subscribing to a newsletter, etc.
Recommendations for Effective Use of Google Analytics
Setting Up Filters
Create filters to exclude your IP address and the IP addresses of company employees to avoid skewing visit statistics:
- Go to Admin > Property > Data Streams.
- Select your data stream and click on Additional Settings > Filtering Settings.
- Add IP addresses that should be excluded from reports.
Using UTM Tags
For effective tracking of traffic sources, use UTM tags in links to your site:
https://yoursite.com/?utm_source=facebook&utm_medium=social&utm_campaign=summer_sale
- utm_source=facebook – indicates the specific traffic source. In this case, it’s Facebook. Other examples: google, instagram, newsletter.
- utm_medium=social – indicates the type of marketing channel. In this case, it’s social networks. Other options: cpc (cost per click), email, banner, referral.
- utm_campaign=summer_sale – name of the specific marketing campaign, in this case “summer sale”. Helps track the effectiveness of different campaigns. Additional parameters (not presented in the example):
- utm_term – used to track keywords in paid search advertising
- utm_content – helps distinguish different elements within a single ad (for example, different buttons)
You can create such links using Google’s Campaign URL Builder tool.
Setting Up Advanced Reports
Create customized reports for deeper analysis:
- In the Reports section, click Library or Create.
- Select the metrics and dimensions you need for the report.
- Save the report for regular use.
Integration with Other Services
To get the most benefit from analytical data, integrate Google Analytics with other services:
- Google Search Console – for analyzing search traffic.
- Google Ads – for tracking the effectiveness of advertising campaigns.
- CRM Systems – for linking visitor data with customer data.
Compliance with Privacy Requirements
When using Google Analytics, you must comply with data privacy legislation:
-
Update your website’s Privacy Policy, indicating that you use Google Analytics to collect anonymous data.
-
Add a Cookie Notice to your site to inform users about data collection and obtain their consent.
-
Set up Data Processing Consent in Google Analytics:
- Go to Admin > Property > Data Streams > your data stream.
- Select Collection Settings > Data Processing Consent.
- Set the appropriate parameters.
Warning: Failure to comply with data protection legislation (GDPR, CCPA, etc.) can result in significant fines.
Common Problems and Solutions
Problems with Google Analytics Installation and Setup
Data not displaying in real-time:
- Incorrect code installation – check that the code is installed on all pages of the site and does not contain errors.
- Ad blocker – disable ad blockers in your browser for testing.
- IP filtering – ensure that your IP address is not excluded from reports.
Incorrect conversion data:
- Improperly configured events – check the event tracking code.
- Event duplication – make sure the same event is not being sent multiple times.
- Problems with conversion setup – check the settings in the “Conversions” section.
Problems with data display in reports:
- Insufficient data – some reports require a certain amount of data.
- Incorrect segment settings – check segmentation settings.
- Delay in data processing – some reports are not updated in real-time but with a delay of up to 24-48 hours.