Track users across multiple subdomains

Say you have Drift installed on two sites, app.example.com and blog.example.com. How do you ensure when a user starts a conversation on your blog they'll pick up the same conversation in your app?

One way is to use something like Segment which will track users across all of your sites. Our Segment integration will piggy back the user ID that Segment is using to track users and re-use that within our widget.

Out of the box the Drift widget uses cookies to track users that are tied to a specific domain; in this case "app.example.com" and "blog.example.com" are two distinct sites. You can add a little extra configuration to your Drift snippet to easily change this behavior...

<!-- Start of Async Drift Code -->
<script>
// ...
drift.SNIPPET_VERSION = '0.3.0';
drift.config({
 cookieDomain: ".example.com"
});
drift.load('xxxxxxxxxxxx');
</script>
<!-- End of Async Drift Code -->

Notice this little bit at the end that we added manually...

drift.config({
 cookieDomain: ".example.com"
});

Now all subdomains of example.com will use the same cookie to track users. Make sure you grab the latest snippet from https://app.drift.com/customize to use this new config method.

The preceding "." is on purpose and acts like a wildcard in cookie-speak.

Let us know if this helps!


Was this article helpful?

Can’t find what you’re looking for?

Talk To Us