Repository navigation
Pass UTM params through to dashboard sign-up #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
goosewin
wants to merge
2
commits into
main
Choose a base branch
from
feature/utm-passthrough-dashboard-bde56f
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * First-touch UTM passthrough to dashboard sign-up. | ||
| * | ||
| * Launch posts link straight to docs pages with UTM params, but sign-ups are | ||
| * tracked on the dashboard, so the params are lost at the hop. Store them on | ||
| * landing and append them to dashboard links on the way out. kernel/website | ||
| * writes the same kernel_utm cookie, so the first touch on either site wins. | ||
| * Mintlify loads every .js file in this directory on every docs page. | ||
| */ | ||
| (function () { | ||
| var COOKIE_NAME = "kernel_utm"; | ||
| var COOKIE_DOMAIN = "kernel.sh"; | ||
| var MAX_AGE = 60 * 60 * 24 * 30; | ||
| var DASHBOARD_HOST = "dashboard.onkernel.com"; | ||
| var UTM_KEYS = [ | ||
| "utm_source", | ||
| "utm_medium", | ||
| "utm_campaign", | ||
| "utm_content", | ||
| "utm_term", | ||
| ]; | ||
|
|
||
| function readStored() { | ||
| try { | ||
| var match = document.cookie.match( | ||
| new RegExp("(?:^|;\\s*)" + COOKIE_NAME + "=([^;]*)") | ||
| ); | ||
| if (!match) return null; | ||
| var parsed = JSON.parse(decodeURIComponent(match[1])); | ||
| return parsed && typeof parsed === "object" ? parsed : null; | ||
| } catch (e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| // Shared across www.kernel.sh and the docs. Off kernel.sh (local preview) | ||
| // the browser would reject the domain, so fall back to a host-only cookie. | ||
| function cookieAttributes() { | ||
| var host = location.hostname; | ||
| var attrs = "; path=/; max-age=" + MAX_AGE + "; SameSite=Lax"; | ||
| if (host === COOKIE_DOMAIN || host.endsWith("." + COOKIE_DOMAIN)) { | ||
| attrs += "; domain=." + COOKIE_DOMAIN; | ||
| } | ||
| if (location.protocol === "https:") attrs += "; Secure"; | ||
| return attrs; | ||
| } | ||
|
|
||
| function captureFirstTouch() { | ||
| if (readStored()) return; | ||
|
|
||
| var params = new URLSearchParams(location.search); | ||
| var utm = {}; | ||
| var found = false; | ||
| UTM_KEYS.forEach(function (key) { | ||
| var value = params.get(key); | ||
| if (value) { | ||
| utm[key] = value; | ||
| found = true; | ||
| } | ||
| }); | ||
| if (!found) return; | ||
|
|
||
| document.cookie = | ||
| COOKIE_NAME + | ||
| "=" + | ||
| encodeURIComponent(JSON.stringify(utm)) + | ||
| cookieAttributes(); | ||
| } | ||
|
|
||
| // Delegated so it covers the navbar buttons and links rendered after | ||
| // client-side navigation. Capture phase rewrites the href before the | ||
| // browser follows it. | ||
| function decorate(event) { | ||
| var link = event.target.closest && event.target.closest("a[href]"); | ||
| if (!link) return; | ||
|
|
||
| var url; | ||
| try { | ||
| url = new URL(link.href, location.href); | ||
| } catch (e) { | ||
| return; | ||
| } | ||
| if (url.hostname !== DASHBOARD_HOST) return; | ||
|
|
||
| var keys = Array.from(url.searchParams.keys()); | ||
| if (keys.some(function (key) { return key.indexOf("utm_") === 0; })) return; | ||
|
|
||
| var utm = readStored(); | ||
| if (!utm) return; | ||
|
|
||
| UTM_KEYS.forEach(function (key) { | ||
| if (utm[key]) url.searchParams.set(key, utm[key]); | ||
| }); | ||
| link.href = url.toString(); | ||
| } | ||
|
|
||
| captureFirstTouch(); | ||
| document.addEventListener("click", decorate, { capture: true }); | ||
| document.addEventListener("auxclick", decorate, { capture: true }); | ||
| })(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attribution cookie ignores tracking preferences
Medium Severity
kernel_utmis a 30-day attribution cookie written and later appended to dashboard links without checking Do Not Track or c15t marketing consent.conceptual.jsalready gates the dashboard attribution handoff on those signals, and the privacy policy says advertising and attribution cookies honor DNT.Additional Locations (1)
utm.js#L96-L99Reviewed by Cursor Bugbot for commit 577769f. Configure here.