Setup the Analytics module in continuous delivery
IMPORTANT: Sitefinity CMS Analytics module is unavailable after July 1, 2024, because it depends on the discontinued Google Universal Analytics. We recommend using Sitefinity Insight and the Script manager (available in Sitefinity CMS 14.3 and later) to integrate another analytics solution.
Register the Analytics module
Before you setup the Analytics module, you must register it in Google Analytics. You must register when you are setting up Analytics for the first time.
Perform the following:
- In Sitefinity CMS backend, navigate to Administration » Settings » Advanced » WebSecurity » RefererValidation.
- In Trusted locations input field, enter accounts.google.com and click Save changes.
- Log in to your Google Analytics account.
- Go to https://code.google.com/apis/console/.
- In the toolbar, click CREATE PROJECT.
- Choose a name for the project and click Create.
- In the toolbar, click on the Notification icon and then click on your newly created project.
- In the Google APIs screen, in the APIs section, click Go to APIs overview.
- Open the Library tab page.
- Under Other, select Google Analytics API.
- In the toolbar, click ENABLE.
- In the upper-right corner, click Create credentials.
- Under Add credentials to your project, click Cancel.
- On the top of the screen, expand Create credentials and click OAuth Client ID.
- In the upper-right corner, click Configure consent screen.
- Select the user type.
You can select External for testing purposes.
- Click Create.
- Fill out the required information, such as App name, User support email, and Developer contact information.
For more information, see Google's documentation about creating the consent screen.
- Go back to the Credentials page, expand Create credentials again, and click OAuth client ID.
- Select Web application.
- Under Authorized JavaScript origins, enter
http://<your website>
- Under Authorized redirect URIs, enter http://<your website>/Sitefinity/marketing/Analytics
- Click Create.
- Copy the generated Client ID and the Client secret.
RESULT: You have registered the Analytics module, you can continue to setup the Analytics module in Sitefinity CMS backend.
Set up the Analytics module
PREREQUISITES: Before you setup the Analytics module, you must have added and configured the Google Analytics widget on at least one page, and the module must have already collected some data.
NOTE: When using the Google Analytics widget, the tracking code is always placed inside the <body> section of the page HTML. If you need to have the tracking code placed inside the <head> tag of the page HTML you must use a JavaScript widget and add the code manually. For more information see JavaScript widget.
When you open the Analytics module for the first time, you need to configure it to show data for the site you want.
To setup Analytics, perform the following:
- Login to Sitefinity CMS and click Marketing » Analytics.
If you have not used the Analytics module before, the Configure Analytics link appears.
- Click Configure Analytics.
- Paste the Client ID and Client Secret that you have copied in Register the Analytics module » Step 18.
NOTE: For specific Client ID and Client Secret, Sitefinity CMS stores only the latest generated refresh token. The reason is Google OAuth 2.0 limitation of 50 refresh tokens per user account. For more information, see Google official documentation about OAuth 2.0 expiration.
- Click Login to Google.
- Allow the created project to view and manage your Google Analytics data.
- In Available accounts, select the view that you have created to track this website.
NOTE: If you have not set the tracking code, provided by Google Analytics on any page of your website or the page where you have set it has not been requested, Sitefinity CMS cannot find account and your domain in the list of Tracked domains.
- In Tracked domains, select the domain of your website.
If you do not see the domain in the list, you can enter it manually.
- Click Save Settings.
The Google Analytics tracking code appears.
- Click Save Settings.
RESULT: You can see website analytics data in the Analytics module.
You can use the same configuration for Google Analytics in all your environments, but receive tracking data only form your production site. Using the following settings, the request to other domains are ignored in the tracked data.
NOTE: Because the configuration files, generated by the Analytics module, are from a different provider, they cannot be stored in the database. Therefore, you cannot configure the module after you deploy the site in the cloud. You must do it before the deployment and the files need to be included in the deployment package.
Perform the following:
- Create an account in Google Analytics or use and existing one.
RECOMMENDATION: Google Analytics recommends that you have one account set for every website that you track.
- In your account, create a new property and set the Default URL to be the URL of your production site.
A property represents a website, mobile application, or device. It is the representation of the resource that is associated with your tracking code.
- In this property, create a view and set its Website URL to be that of your production site.
The view is your access point to reports.
- Add a filter for the newly created view.
It will filter the incoming data, so that only data from your production domain will be used.
Perform the following:
- In Google Analytics, navigate to the Admin section.
- Select your Account, Property, and View.
- In the View column, click Filters » ADD FILTER.
- In Filter Name, choose a name for the filter.
- In Filter Type, select Predefined.
- In Select filter type, select Include only.
- In Select source or destination, select traffic to the hostname.
- In Select expression, select that contains or that are equal to, depending on the setup you need.
- In Hostname, enter the address of your production website.
- Click Save.
- Perform procedure Set up the Analytics module.
- In Step 6, in Available accounts dropdown box, select the view that you have created.
- In Step 7, in Tracked domains, select the domain of the production website.
NOTE: If you have not set the tracking code, provided by Google Analytics on any page of your website or the page where you have set it has not been requested, Sitefinity CMS your domain in the list of Tracked domains.
RESULT: Sitefinity CMS Analytics module will display data from your production environment only, regardless of that you are using the same Analytics settings on all of your environments.