Conversion pixel engine (Marty approved 2026-10-23): goals with public pixel ids, click ids on every ad click (lsclk, 'a'+11 hex), spin links pass the ad click on, landing tag /t.js + goal pixel /cv.gif /cv.js matching url > stored > cookie > 24 h soft key, once per click, 30-day window, owner check, rate limits, goal postbacks (event 'goal'), member + signed partner APIs for InstantAdPay
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
/* LinkSpin landing tag (conversion pixel, 2026-10-23). Paste once on your landing page:
|
||||
* <script async src="https://linkspin.app/t.js?px=YOUR_PIXEL_ID"></script>
|
||||
* It reads the click id LinkSpin or InstantAdPay put on the link (lsclk, lsid or clickid in the address), keeps it on YOUR
|
||||
* site for 30 days (localStorage + a first-party cookie, both named ls_clk), copies it into hidden form fields named lsclk,
|
||||
* lsid or clickid, and adds it to links that stay on your site. Nothing personal is read or stored.
|
||||
* It never throws and never blocks your page: every step is wrapped, and it only runs after the page has its scripts.
|
||||
*/
|
||||
(function () {
|
||||
try {
|
||||
var KEY = 'ls_clk', RX = /^[a-z0-9]{6,24}$/i, DAYS = 30, W = window;
|
||||
var me = document.currentScript;
|
||||
if (!me) { var all = document.getElementsByTagName('script'); for (var i = all.length - 1; i >= 0; i--) { if (/\/t\.js(\?|$)/.test(all[i].src || '')) { me = all[i]; break; } } }
|
||||
if (!me || !me.src) return;
|
||||
var src = new URL(me.src, location.href), base = src.origin, px = src.searchParams.get('px') || '';
|
||||
var framed = true; try { framed = W.top !== W.self; } catch (e) { framed = true; }
|
||||
var https = location.protocol === 'https:';
|
||||
function setCookie(v) {
|
||||
try { document.cookie = KEY + '=' + v + '; path=/; max-age=' + (DAYS * 86400) + (https ? (framed ? '; SameSite=None; Secure' : '; SameSite=Lax; Secure') : '; SameSite=Lax'); } catch (e) {}
|
||||
}
|
||||
function stored() {
|
||||
var v = '';
|
||||
try { var j = JSON.parse(W.localStorage.getItem(KEY) || 'null'); if (j && RX.test(j.id || '') && Date.now() - (j.ts || 0) < DAYS * 864e5) v = j.id; } catch (e) {}
|
||||
if (!v) { try { var m = /(?:^|;\s*)ls_clk=([a-z0-9]{6,24})/i.exec(document.cookie || ''); if (m) v = m[1]; } catch (e) {} }
|
||||
return v;
|
||||
}
|
||||
function keep(v) { try { W.localStorage.setItem(KEY, JSON.stringify({ id: v, ts: Date.now() })); } catch (e) {} setCookie(v); }
|
||||
var q = new URLSearchParams(location.search);
|
||||
var fresh = q.get('lsclk') || q.get('lsid') || '';
|
||||
var id = '';
|
||||
if (RX.test(fresh)) { id = fresh; keep(id); }
|
||||
else {
|
||||
id = stored();
|
||||
// a generic clickid only when we hold nothing better (it may be another network's id)
|
||||
var g = q.get('clickid') || ''; if (!id && RX.test(g)) { id = g; keep(id); fresh = g; }
|
||||
}
|
||||
// tell LinkSpin the landing happened (sets its own 30-day cookie and the 24 h match); only for a fresh id
|
||||
if (fresh && RX.test(fresh) && /^px[a-f0-9]{10}$/.test(px)) { try { var im = new Image(1, 1); im.src = base + '/t.gif?px=' + px + '&c=' + encodeURIComponent(fresh) + '&r=' + Math.random().toString(36).slice(2, 8); } catch (e) {} }
|
||||
var LS = W.LinkSpin = W.LinkSpin || {};
|
||||
LS.clickId = function () { return id || stored(); };
|
||||
LS.goal = function (pixelId, name, value) {
|
||||
try {
|
||||
var c = id || stored(); var u = base + '/cv.gif?px=' + encodeURIComponent(pixelId) + (name ? '&goal=' + encodeURIComponent(name) : '') + (value != null && value !== '' ? '&value=' + encodeURIComponent(value) : '') + (c ? '&c=' + encodeURIComponent(c) + '&m=stored' : '') + '&r=' + Math.random().toString(36).slice(2, 8);
|
||||
var im2 = new Image(1, 1); im2.src = u;
|
||||
} catch (e) {}
|
||||
};
|
||||
if (!id) return;
|
||||
var NAMES = ['lsclk', 'lsid', 'clickid'];
|
||||
function fillForms(root) {
|
||||
try {
|
||||
var f = (root || document).querySelectorAll('input[name="lsclk"],input[name="lsid"],input[name="clickid"]');
|
||||
for (var i = 0; i < f.length; i++) if (!f[i].value) f[i].value = id;
|
||||
} catch (e) {}
|
||||
}
|
||||
fillForms();
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function () { fillForms(); });
|
||||
document.addEventListener('submit', function (e) { fillForms(e.target); }, true);
|
||||
var host = location.hostname.replace(/^www\./, '');
|
||||
function decorate(a) {
|
||||
try {
|
||||
if (!a || !a.href || a.getAttribute('data-ls-skip') != null) return;
|
||||
var u = new URL(a.href, location.href);
|
||||
if (!/^https?:$/.test(u.protocol) || u.hostname.replace(/^www\./, '') !== host) return;
|
||||
if (u.pathname === location.pathname && u.search === location.search && u.hash) return; // an anchor on this page
|
||||
for (var i = 0; i < NAMES.length; i++) if (u.searchParams.has(NAMES[i])) return;
|
||||
u.searchParams.set('lsclk', id); a.href = u.toString();
|
||||
} catch (e) {}
|
||||
}
|
||||
function onClick(e) { try { var a = e.target && e.target.closest ? e.target.closest('a[href]') : null; if (a) decorate(a); } catch (er) {} }
|
||||
document.addEventListener('click', onClick, true);
|
||||
document.addEventListener('auxclick', onClick, true);
|
||||
} catch (e) { /* never break the member's page */ }
|
||||
})();
|
||||
Reference in New Issue
Block a user