If you use the universal tracking code——analytics.js, which has include subdomain tracking turned on by default, you can use the tracking code directly, but you also need to configure something in Google Analytics, The following picture is the universal tracking code:
The auto inside means that the cookie is automatically generated under the top-level domain, that is, the two sub-domains will share the cookies in the same top-level domain. For example, if your website address is blog.bbbccss.com
, analytics.js will set the cookie domain to bbccss.com,
another website is new.bbccss.com, analytics .js will set the cookie domain to .bbccss.com, So if different subdomains deploy the same piece of tracking code, they use the same cookie, allows hits from all subdomains to share the same first-party cookie,
If you use the recommended JavaScript snippet that Google Analytics provides you, this is already set for you,We don’t need to make changes to the Google Analytics tracking code to use it directly:
If you are in Google Tag Manager, you need to do some configuration:
You can also use Google Analytics settings, which are enabled by default:
We still need to do some configuration in Google Analytics,In Google Analytics,Select “Admin” → “Tracking Info” → “Exclude Referral List” → “Add Referral List” ,and ensure that all domains added to the Exclude Referral List.
When a user jumps from one domain name to another, it will send a referral to Google Analytics. If it is different from its own website, it will generate a new session. The Exclude Referral List is to prevent the creation of a new session. After this setting, the user will not generate a new session when jumping in a different subdomain. What happens if there is no setting?
Take a look at the following example:
- One user visit: http://blog.bbccss.com
- Then visit: http://new.bbccss.com
- Last visit: http://blog.bbccss.com
CookieDomain (Which means is set as auto)and referral traffic are not set: 2 users, 3 sessions will be recorded
If the cookie domain is set but the referral traffic is not set,:1 user, 3 sessions will be recorded.
If the cookie domain and referral traffic are both set,:1 user, 1 session will be recorded.
Therefore, subdomain configuration must be configured to exclude referral lists.