- Page views, including single-page app navigation
- First-touch and last-touch UTM attribution
- Ad click IDs such as
gclid,fbclid, andttclid - Paid, organic, social, AI search, referral, and direct traffic
- Browser, device, geography, and performance data
1. Add the SDK
We recommend loading the browser SDK from the Linkrunner CDN. This lets Linkrunner ship fixes and updates without requiring you to change or redeploy your integration. The direct script tag and the Next.js helper both loadhttps://cdn.linkrunner.io/web/v1/lr.js by default. The npm package provides the typed Next.js component and event methods, while the browser SDK still stays current through the CDN.
- CDN script (preferred)
- Next.js App Router
- Next.js Pages Router
Add this script before the closing
</head> tag. Replace YOUR_WEB_SDK_TOKEN with the token provided by Linkrunner.2. Identify users and track events
Callidentify after a user signs in or when you otherwise know their identity. Use a stable internal user ID rather than an email address or phone number.
localStorage and includes it as user_id on later events.
Track a custom event with track:
signup event:
identify does not add the user ID to events that were already captured.
Calls made before the SDK finishes loading are queued and replayed after initialization.
3. Verify the integration
Setdata-debug="true" while testing:
- In Console, confirm that messages start with
[Linkrunner]and includeInitialized. - In Network, confirm that page views and events send a
POSTrequest to/web/ingest. - Trigger a test event and confirm the console reports
Sent via fetch.
localhost, 127.0.0.1, and [::1]. Remove data-debug="true" after testing.
Configuration
Script tag attributes
You can also set the same options before the script loads:
data-domain or data-endpoint, events go to https://api.linkrunner.io/web/ingest.
First-party collection
Some ad blockers stop requests to analytics domains. First-party collection sends events through your own domain instead.Proxy through your website
This is the most reliable option because both the SDK and event endpoint use paths on your website. For Next.js, add two rewrites:LinkrunnerScript at those routes:
Point a subdomain at Linkrunner
Use this option when you cannot add proxy routes to your website.1
Register the subdomain
In the Linkrunner dashboard, open Settings → Manage Domains and add the collection subdomain you want to use, such as
lr.example.com.2
Add the DNS record
Add a CNAME record with your DNS provider:Linkrunner issues the TLS certificate on the first request for a registered subdomain.
3
Configure the SDK
Add For Next.js, use the
data-domain to the script tag:domain prop:4
Verify the endpoint
Run this request before relying on the subdomain:Expect a
204 response with an access-control-allow-origin header. Then confirm in your browser’s Network tab that event requests go to https://lr.example.com/web/ingest.Set
data-domain to a hostname, not a URL. The SDK accepts a scheme or trailing slash, but it always normalizes the value to https://HOST/web/ingest. Use data-endpoint only when you control the full proxy path.Attribution storage
The 24-hour
localStorage copy preserves last-touch UTMs when a payment gateway or 3D Secure flow returns the visitor in a new tab.
Troubleshooting
The SDK says the token is invalid
The SDK says the token is invalid
Confirm that you are using the Web SDK token provided by Linkrunner. Mobile SDK project tokens do not work with the Web SDK. If you need a token, contact support@linkrunner.io.
Page views are duplicated
Page views are duplicated
Load the SDK once. In Next.js, put
LinkrunnerScript in the root layout or _app.tsx, not on individual pages. The SDK already tracks SPA navigation by default.Events are blocked in the browser
Events are blocked in the browser
Use first-party collection. A same-origin proxy is the strongest option. A CNAME may still be detected by browsers that inspect DNS records.
A payment or other trusted event can be sent from the browser
A payment or other trusted event can be sent from the browser
Do not trust client-side events for payments, entitlements, or other sensitive state changes. Send those events from your backend with the Event Capture API or Revenue Tracking API.
More resources
npm package
View the package, current version, and full SDK reference.
GitHub repository
Read the source code and release history.
Shopify setup
Install Web Attribution on a Shopify storefront and checkout.