Link Studio docs › Tracking

Tracking script reference

Everything a developer needs to install the tracking script, name pages and clicks, and fit it into a consent flow.

Installing the script

Add the snippet to every page, ideally in the <head>. Copy it from Pages, then Set up tracking, so it carries your own key.

<script>window.linkStudio=window.linkStudio||{q:[]};["page","track","identify","reset"].forEach(function(m){window.linkStudio[m]=window.linkStudio[m]||function(){window.linkStudio.q.push([m,arguments])}})</script>
<script src="https://link-studio-connect.link-studio-connector.workers.dev/t.js" data-key="YOUR_KEY" defer></script>

The first line keeps any calls your code makes before the script has loaded, and replays them once it has. Keep it above the script tag.

AttributeWhat it does
srcLoads the script.
data-keyYour workspace’s tracking key. Without it, the script does nothing.
data-domainsOptional. Your other domains, separated by commas, so one visitor stays one visitor across them.
deferLets your page show first, then starts tracking.

Naming pages

Give each page template one short name, the way a person would say it: Homepage, Product, Cart, Checkout, Pricing.

<meta name="link-studio-page" content="Checkout">

Single page apps

Route changes are followed for you. Set the same meta tag on each route, or name the page in code when the route mounts:

window.linkStudio?.page("Checkout");

In the Next.js App Router, you can set the tag from each page.tsx:

export const metadata = { other: { "link-studio-page": "Checkout" } };

Naming key moments

Named moments become funnel steps, goals and Board cards. Name them in the past tense, like Signed up, Started trial, Booked call or Purchased.

Without code, add data-ls-event. On a button or link it fires on click. On a form it fires on submit.

<button data-ls-event="Booked call">Book a call</button>
<form data-ls-event="Submitted lead">…</form>

From code, call track once the action has succeeded, with up to 20 properties made of text, numbers or true and false:

window.linkStudio.track("Started trial", { plan: "Pro", seats: 3 });

Signed in people and sales

After someone signs up or logs in, tell Link Studio who they are with your own user ID. Emails are ignored. Call reset when they log out.

window.linkStudio.identify(user.id);
window.linkStudio.reset();

To credit a sale to the link that brought the buyer, even when nobody signed in, add the values from attribution to your checkout’s metadata, for example on a Stripe Checkout Session or as Shopify cart attributes:

const metadata = { ...window.linkStudio.attribution() };

Several domains

Subdomains of one site, like www, app and shop, already count as one visitor. For separate domains, list the others in data-domains on each site, and links between them carry the visitor across.

<script src="…/t.js" data-key="YOUR_KEY" data-domains="brandshop.com" defer></script>

Naming and skipping clicks

Clicks on links and buttons are named by their text. To choose the name yourself, add data-ls-click:

<button data-ls-click="Add to cart">Add</button>

To leave an element out completely, add data-ls-ignore to it or to any parent.

<nav data-ls-ignore>…</nav>

Privacy and consent

  • The script keeps a random visitor ID in a first party cookie on your own domain, so your subdomains share one visitor, and in the browser’s storage. It keeps the last link clicked in the browser’s storage.
  • If you call identify, your user ID is kept the same way until you call reset.
  • A clicked link counts toward later visits and sales for 30 days.
  • It never reads names, emails or anything typed into a form.
  • Page addresses are sent without their query strings. Only the campaign tags are read from them.
  • The visitor’s location comes from their connection when the visit arrives. Their address is never stored.

FAQs

Can I load the Link Studio tracking script more than once?

Yes, it is safe. The Link Studio script only starts once per page, however many times it loads.

Does the Link Studio tracking script work with Shopify, Webflow or Wix?

Yes. Paste the Link Studio snippet into the custom code area that loads on every page of your Shopify, Webflow or Wix site.