Support

Using GoSquared on Subdomains

🍪 GoSquared uses tracking cookies to keep track of new and returning visitors on your site. By default, GoSquared will set a new tracking cookie on each subdomain that a visitor visits – even if you have installed the same tracking code on all of them.

🍪 If you want to change this behaviour so that GoSquared uses the same tracking cookie across all of your subdomains you'll need to add an extra line of code that forces GoSquared to do this – see guide below.

🍪 An example use-case for this would be tracking a website and an app on different subdomains of the same domain.

Why use the same tracking cookie across subdomains?

GoSquared uses cookie tracking to remember if a visitor is brand new to your site, or returning. We also use cookies to remember a visitor's conversation history in Inbox. This means that all their conversations can be stored under the same Contact profile, and the visitor can always pick up a conversation where they left off last time.

So, if you want to avoid duplicate Contact profiles in GoSquared, maintain message history when a visitor moves across subdomains, and also correctly report new vs returning visitor numbers, it's a good idea to read this guide!


How to force GoSquared to use the same tracking cookie

In order to avoid duplicate user profiles being created, and to correctly maintain message histories, you can force GoSquared to use the same tracking cookie across all your subdomains.

To do this you'll need to use the cookieDomain configuration option in your GoSquared tracking code. After the main tracking code snippet add this extra line, replace the 'my-main-domain.com' part with your site's root domain.

_gs('set', 'cookieDomain', '.my-root-domain.com');

Note: you'll need to add this extra line to every subdomain you want to track and also your main root domain.

You can read more about technical config options in our API documentation here.

cookieDomain example

In this example:

checkout.mywebsite.com is a subdomain of mywebsite.com

Therefore if we wanted to maintain a consistent People profile and message history across both, we would need to set the cookieDomain config option to always use the root domain. This would mean adding this extra line of code underneath the main GoSquared code snippet. You would add this to every page you want to track, including on the root domain:

<script>
  !function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
  arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
  d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';q.parentNode.
  insertBefore(d,q)}(window,document,'script','_gs');

  _gs('GSN-XXXXXX-X');
  _gs('set', 'cookieDomain', '.mywebsite.com');
</script>

The . is important!


Setting the cookieDomain in Segment

You can set the cookie domain in Segment by logging into your Segment account and selecting GoSquared from your list of active destinations. Click through to the GoSquared settings and select the cookieDomain option.

Segmenting your subdomain traffic

You can add the same tracking code to as many subdomains as you like and their Analytics will all be tracked together in the same project. This can be useful for creating a 'total traffic' overview dashboard. However your new vs returning visitors numbers may be inaccurate unless you use the cookieDomain code option explained above.

Alternatively, you can create a new project for each subdomain and track them separately with a different tracking code on each subdomain. This can be useful if your subdomains are relatively independent from each other.

If you want to separate your traffic between subdomains then we would recommend using one tracking code on all your subdomains to create a global traffic dashboard, and then add a second tracking code to each subdomain. This would create a new separate dashboard for each subdomain.

Our tracker documentation on multiple tracking codes explains how to implement this feature.