deliverability letter

Tracking Across Subdomains

Hello and Welcome to Tracking Across Subdomains with your host, Scott.

So you are tracking people on your main site but when they get sent to your different domains (say example.com —> app.example.com), all that sweet sweet tracking data is not attributed to the same user. You're now noticing two anonymous identities appearing in Bento when really that should be just one.

Why does that happen?

A few years ago, web browsers stopped allowing cookies to be tracked across domains. When this happened, Bento moved logging visitor data to localStorage which also doesn't persist across domains.

This problem persists in ALL analytics tools and is probably messing up your data, especially when it comes to ad attribution and behaviour tracking.

Fortunately, we've got a super simple solution for it.

To do this we will need to add a bit of code on your main site that waits for Bento's JS SDK to load and then adds a unique identifier to all links going to any subdomain you declare.

This ensures the visitors data gets passed from site to site.

So first things first; open up the HTML for your site in your editor of choice and find where you have the Bento code. Right beneath that all you need to do is paste the code below inside a script tag:

window.addEventListener("bento:ready", function () { if (typeof(bento$) != 'undefined') { bento$(function() { bento.trackSubdomains(['test.example.com']) }); } })

As a side note, this script can go anywhere in your code as long as you're already loading Bento JS SDK elsewhere. I like to keep them together as it keeps the code cleaner and makes it easier to find in the future.

Once bento.trackSubdomains runs it'll update all outgoing links with a bento_uuid params.

PLEASE CHECK ALL YOUR LINKS AFTER RUNNING THIS TO ENSURE NONE ARE BROKEN.

And that's it. When you refresh the page everything should #justwork. If it doesn't, come over to Discord and let us know so we can debug it with you.

For all you audio/visual learners out there here is a quick video which explains everything as well.

If you have any problems, please don't hesitate to reach out on Discord so we can help.