Google Analytics is a powerful tool for gaining insights into website traffic and user interactions. By integrating it with Atlas, organizations can leverage a more refined analysis of their intranet. This article will guide you through the process of setting up Google Analytics with Atlas, focusing on configuring user variables and tracking specific Atlas webparts.
Step 1: Setting Up Google Analytics and Google Tag Manager
First, ensure you have both Google Analytics and Google Tag Manager accounts. If you don't have these set up yet, here's how you can get started:
-
Google Analytics:
- Sign up or log in at Google Analytics.
- Create a new property for your website, and save the snipped script to be inserted in Atlas for later.
-
Google Tag Manager:
- Visit Google Tag Manager and sign up or log in.
- Create a new container for your website, selecting 'Web' as where to use the container, and save the script to be inserted in Atlas for later.
After setting up both accounts, add the snippet codes to your Atlas using the tenant property Atlas.Analytics.Scripts. After refreshing the cache of the Atlas Navigation, you will start seeing user activity in Google Analytics.
Step 2: Configuring User Variables in Google Tag Manager
You can customize the data collected using Google Tag Manager. User variables in Google Tag Manager allow you to store and use data about your website's users. This can be anything from user settings to session-specific data. Here is an example of how to set up a user variable to track the email address of the user. Follow these steps:
-
Navigate to Variables:
- In your Google Tag Manager dashboard, select 'Variables' from the sidebar.
- Click 'New' under the User-Defined Variables section.
-
Configure the User Variable:
- Choose a variable type Custom Javascript.
- Configure the variable settings according to your needs.
- Create a variable named
userEmail
- Add the following Custom JavaScript:
-
function(){
return "undefined"!=typeof SP&&(e=SP.PageContextInfo.get_$2()),"undefined"!=typeof _spComponentLoader&&(_spComponentLoader._instance._serviceScope.consume({id:"sp-page-context:PageContext_8",name:"sp-page-context:PageContext"}))._user.email
}
-
Configure the Tag to Send Data to Google Analytics:
- Set up a Tag (Page views or a custom tag triggered on click event) to send the user email data.
Step 3: Tracking Atlas webparts
To track specific Atlas webparts, you can use a user variable to identify what web part the user clicked. Use Google Tag Manager's ability to fire tags based on custom triggers:
-
Create the User Variable:
- Follow the same steps in Step 2, using s
SP-feature-tag
with the following Javascript Code: -
function(){
var e = {{Click Element}};
var closestTile = e.closest('[data-sp-feature-tag]');
return closestTile.dataset.spFeatureTag;
}
- Follow the same steps in Step 2, using s
-
Set Up a Trigger:
- Choose 'Triggering' and click 'New' to create a trigger.
- Set up a trigger that fires in the conditions where
SP-feature-tag
is present. This might be a Page View or Custom Event.
-
Configure the Tag to Send Data to Google Analytics:
- Create a tag that sends the data to Google Analytics when the trigger is fired.
Step 4: Testing and Deployment
Before going live, test your configuration:
- Use the 'Preview' mode in Google Tag Manager to ensure that tags are firing correctly as you navigate your site.
- Check-in Google Analytics to see if the data appears as expected.
Once everything is tested and working, publish your changes in Google Tag Manager.
Comments
0 comments
Article is closed for comments.