Skip to content
Install the Capture Script

Install the Capture Script

Availability: Conversion tracking is available on Professional and Agency plans.

When conversion tracking is on for a link, Shortn adds a click id to the destination URL:

https://example.com/signup?snt_click_id=clk_...

Add the capture script to the destination site so it can keep the click id until signup or checkout:

<script
  src="https://app.shortn.link/static/js/conversion-capture.js"
  data-track-endpoint="/api/shortn-conversion"
  data-consent-cookie="shortn_consent"
  data-form-enrichment="true">
</script>

The script reads snt_click_id from the URL and keeps it in a first-party cookie and localStorage (shortn_click_id), with any UTM parameters (shortn_utm_params). It keeps the click id for its attribution window, at most 90 days. Whether a newer click replaces the stored one follows the workspace’s attribution model (first or last touch).

Consent

By default the script stores nothing until the visitor consents (data-consent-mode="required"). Grant consent in one of two ways:

  • From your consent banner: call window.shortn.conversion.grantConsent() when the visitor accepts, and revokeConsent() when they withdraw. Call syncConsent() after your banner changes its own cookie.
  • Through a cookie: set data-consent-cookie to a cookie your consent tool writes. The value v1.granted turns capture on and v1.denied turns it off (change them with data-consent-granted-value and data-consent-denied-value).

If your site does not need consent for this purpose, set data-consent-mode="not-required" (without data-consent-cookie). getConsentState() returns the current state.

Form enrichment

With data-form-enrichment="true", the script adds hidden shortn_click_id and UTM fields to forms on the page, including forms added later. It only passes on values from the URL; it does not collect location, device, browser, page URL or referrer. Add data-shortn-ignore="true" to a form to skip it.

Checkout links

The script adds the stored click id to Dodo Payments checkout links and Stripe Payment Links when a visitor follows them. Set data-checkout-links="false" to turn this off. See Attribute hosted checkouts for every checkout flow.

Browser API

const clickId = window.shortn.conversion.getClickId();
const attribution = window.shortn.conversion.getAttribution(); // { click_id, utm }

Use these only to pass the click id to your own backend. trackLead, trackSale and convert post events to data-track-endpoint on your site; see Send conversion events. Other functions: capture(), clearClickId(), clearAttribution(), checkoutURL(url) and subscribe(callback).

Attributes

AttributeDefaultDescription
data-track-endpointnoneYour backend endpoint that forwards events to Shortn. Required for trackLead, trackSale and convert.
data-consent-moderequiredrequired or not-required.
data-consent-cookienoneCookie your consent tool writes.
data-consent-granted-valuev1.grantedCookie value that grants consent.
data-consent-denied-valuev1.deniedCookie value that denies it.
data-cookie-domaincurrent hostShare the cookie across subdomains, for example .example.com.
data-cookie-days90How long to keep the click id, 1 to 90 days; never longer than the click’s attribution window.
data-custom-utm-paramsnoneMore UTM-style parameters to keep, comma-separated, for example utm_team,utm_variant.
data-form-enrichmentfalseAdd hidden click id and UTM fields to forms.
data-checkout-linkstrueAdd the click id to Dodo Payments and Stripe checkout links.
data-debugfalseLog what the script does to the browser console.

Cloaked links

The capture script can’t reliably keep the click id for links with cloaking on: the destination runs inside a frame, and browsers keep framed storage apart. Turn off cloaking for links you track conversions on.

Last updated on