/* ===================================================================== GEMS attribution script, all school websites (HubSpot and WordPress) Implements "Attribution Model Specification" (Final v2, approved by Marketing): a Last Paid UTM record plus a rolling Attribution History of up to five touchpoints, delivered to every enquiry form. No link rewriting. v8 (changes from v7) - New model. The paid > organic > direct ranking and the first-touch cookie are gone. Replaced by two stores: Last Paid UTM most recent paid visit, valid 90 days from that visit. Only a paid visit writes it. Attribution History up to 5 touchpoints, oldest to newest, each valid 90 days from its own timestamp. - Visits are session based. Only the landing page of a session is evaluated. A session ends after 30 minutes without a page view. A new visit also starts mid-session when a page view arrives from outside the site with UTMs or a paid click ID that differ from the current session's. - Paid = utm_medium in CONFIG.PAID_MEDIUMS, or a paid click ID in the landing URL (gclid, gbraid, wbraid, fbclid, ttclid, li_fat_id, msclkid, sccid). - New non-paid sources from the referrer: organic social ( / social) and AI assistants ( / ai_assistant), matched before search engines. - Direct visits are never recorded (previously sent as direct / none). - UTM values are trimmed and lowercased before anything else. - Form delivery follows spec section 3: valid Last Paid UTM, else the most recent touchpoint, else empty fields. - GA client id (from the _ga cookie) is now sent. - Storage moved from cookies to localStorage (same per-domain reach as the v7 cookies, no 4 KB limit for the history). - Old gwa_attr / gems_attr cookies are migrated once, then removed. Not in the approved spec, so no longer stored or sent: gad_source, gad_campaignid. Assumptions made where the spec is silent (all in CONFIG, easy to change) - Source / medium derived from a click ID when UTMs are missing: only gclid -> google / cpc is given in the spec, the rest are assumed. - EXCLUDED_REFERRERS: the spec names "payment gateway and authentication redirects" without listing domains. - A landing page reached from inside the site (session timed out, then an internal click) is not a trackable visit. - Attribution Type, Campaign ID, Click ID type, Landing Page, Timestamp and the history are computed and exposed, but are only delivered to a form once a field name is entered in the field maps. Where to put it HubSpot sites Design Manager > theme > js > template_main.js (end of file), or Settings > Content > Pages > domain > Site footer HTML inside