Track clicks on the client-side using query parameters
@dub/analytics
script, you can track clicks on the client-side using query parameters (e.g. ?via=john
, ?ref=jane
).
A few use cases include:
trackClick()
function inside your application code.@dub/analytics
script:
Add a custom domain to your Dub workspace
yourcompany.link
for free.This is the domain that you’ll use for your short links on Dub.Allowlist your site's domain
example.com
: Tracks traffic only from example.com
.*.example.com
: Tracks traffic from all subdomains of example.com
, but not from example.com
itself.localhost
to the Allowed
Hostnames list temporarily. This will allow local events to be ingested by
Dub. Don’t forget to remove it once you’re ready to go live!Install the Dub client-side SDK
Parameters
first-click
: The first click model
gives all the credit to the first touchpoint in the customer journey.last-click
: The last click model gives all the credit to the last
touchpoint in the customer journey.?via=abc123
).(Optional, but recommended): Set up a reverse proxy
Verify your setup
https://go.example.com/abc123
, you’ll need to append ?via=abc123
to the URL.Once you’ve done that, check if the following is true:/track/click
request in your browser’s Network tab (and no errors in the Console tab).dub_id
cookie is being set upon a successful /track/click
request.dub_partner_data
cookie in the following format:
name
and image
fields in the partner data are URL-encoded when stored
in the cookie. Make sure to decode these values using decodeURIComponent()
when accessing them from the cookie. However, if you’re using js-cookie
as
shown in the example below, the decoding is handled automatically for you.js-cookie
– here’s an example:
trackClick()
functionAttribute | Type | Description |
---|---|---|
timestamp | string | The timestamp of the click event |
id | string | The unique ID of the click event |
url | string | The destination URL that the link resolved to – this can vary if geo/device-targeting is enabled |
continent | string | The continent of the user who clicked the link |
country | string | The country of the user who clicked the link |
city | string | The city of the user who clicked the link |
device | string | The device of the user who clicked the link |
browser | string | The browser of the user who clicked the link |
os | string | The operating system of the user who clicked the link |
referer | string | The referrer of the user who clicked the link |
refererUrl | string | The full referrer URL of the user who clicked the link |
qr | boolean | Whether the click event was triggered by a QR code scan |
ip | string | The IP address of the user who clicked the link (non-EU users only) |