|
| 1 | +--- |
| 2 | +/* |
| 3 | + * First-touch acquisition cookie for cross-app payment attribution. |
| 4 | + * |
| 5 | + * The marketing site (open-design.ai) and the vela checkout/wallet page |
| 6 | + * (served same-origin at open-design.ai/cloud/*) share the open-design.ai |
| 7 | + * domain. This captures utm_* + the external referrer on landing and stores a |
| 8 | + * FIRST-TOUCH cookie (`od_attr`) so the checkout page can read it back and |
| 9 | + * attribute the payment to the originating traffic source — closing the |
| 10 | + * "external source -> payment" gap (per-channel/per-campaign revenue). |
| 11 | + * |
| 12 | + * - Forward-only: only affects traffic after this ships. |
| 13 | + * - First-touch wins: never overwritten, so the original source survives |
| 14 | + * later internal navigation. |
| 15 | + * - Falls back to the referrer host when no utm is present, so organic |
| 16 | + * search (google/bing) is attributed too, not just tagged links. |
| 17 | + * - Sets nothing for true direct traffic (no utm, no external referrer). |
| 18 | + * |
| 19 | + * Injected alongside PostHog on every page. No PostHog dependency. |
| 20 | + */ |
| 21 | +--- |
| 22 | +<script is:inline> |
| 23 | +(function () { |
| 24 | + try { |
| 25 | + var COOKIE = 'od_attr'; |
| 26 | + // First-touch: if we already captured a source, keep it. |
| 27 | + if (document.cookie.indexOf(COOKIE + '=') !== -1) return; |
| 28 | + |
| 29 | + var qs = new URLSearchParams(window.location.search); |
| 30 | + var get = function (k) { var v = qs.get(k); return v ? String(v).slice(0, 120) : ''; }; |
| 31 | + var utmSource = get('utm_source'); |
| 32 | + |
| 33 | + var ref = ''; |
| 34 | + try { |
| 35 | + if (document.referrer) { |
| 36 | + var rh = new URL(document.referrer).hostname; |
| 37 | + if (rh && rh.indexOf('open-design') === -1) ref = rh.slice(0, 120); |
| 38 | + } |
| 39 | + } catch (e) {} |
| 40 | + |
| 41 | + // Nothing to attribute (direct, no utm, no external referrer) -> skip. |
| 42 | + if (!utmSource && !ref) return; |
| 43 | + |
| 44 | + var data = { |
| 45 | + s: utmSource, m: get('utm_medium'), c: get('utm_campaign'), |
| 46 | + ct: get('utm_content'), tm: get('utm_term'), |
| 47 | + ref: ref, lp: (location.pathname || '/').slice(0, 80), t: Date.now() |
| 48 | + }; |
| 49 | + |
| 50 | + // 30-day first-touch window. Use the apex domain in production so the |
| 51 | + // same-origin checkout page (open-design.ai/cloud/*) can read it; on |
| 52 | + // preview/dev hosts fall back to a host-only cookie so it still works. |
| 53 | + var host = location.hostname || ''; |
| 54 | + var domainAttr = /(^|\.)open-design\.ai$/.test(host) ? ';domain=.open-design.ai' : ''; |
| 55 | + var secure = location.protocol === 'https:' ? ';Secure' : ''; |
| 56 | + document.cookie = COOKIE + '=' + encodeURIComponent(JSON.stringify(data)) + |
| 57 | + ';path=/;max-age=' + (60 * 60 * 24 * 30) + domainAttr + ';SameSite=Lax' + secure; |
| 58 | + } catch (e) {} |
| 59 | +})(); |
| 60 | +</script> |
0 commit comments