___INFO___ { "displayName": "Linkube Conversion Tracking", "categories": ["ANALYTICS", "CONVERSIONS"], "id": "cvt_linkube_conversion_v2", "type": "TAG", "version": 2, "containerContexts": ["WEB"], "description": "Track conversion events (purchase, signup, add_to_cart, etc.) and attribute them back to Linkube short-link clicks." } ___TEMPLATE_PARAMETERS___ [ { "type": "TEXT", "name": "installationToken", "displayName": "Publishable installation token", "simpleValueType": true, "valueValidators": [{"type": "NON_EMPTY"}], "help": "The publishable browser token revealed under Workspace → Setup & Attribution. It starts with lkpub_.", "valueHint": "lkpub_xxxxxxxxxxxxxxxx" }, { "type": "TEXT", "name": "eventId", "displayName": "Stable Event ID", "simpleValueType": true, "valueValidators": [{"type": "NON_EMPTY"}], "help": "A stable order, transaction, or application event ID. Reuse it for retries of the same business event." }, { "type": "TEXT", "name": "eventName", "displayName": "Event Name", "simpleValueType": true, "defaultValue": "purchase", "valueValidators": [{"type": "NON_EMPTY"}], "help": "Conversion event name (e.g. purchase, signup, add_to_cart). Use a Data Layer Variable to set this dynamically." }, { "type": "TEXT", "name": "value", "displayName": "Value (optional)", "simpleValueType": true, "help": "Monetary value of this conversion (e.g. 49.99). Use a Data Layer Variable for dynamic order totals. Leave empty if not applicable." }, { "type": "TEXT", "name": "currency", "displayName": "Currency", "simpleValueType": true, "defaultValue": "USD", "help": "ISO 4217 currency code (USD, EUR, GBP …)." }, { "type": "SIMPLE_TABLE", "name": "customData", "displayName": "Custom Data (optional)", "simpleTableColumns": [ { "defaultValue": "", "displayName": "Key", "name": "key", "type": "TEXT" }, { "defaultValue": "", "displayName": "Value", "name": "value", "type": "TEXT" } ], "help": "Optional key-value pairs attached to the event (e.g. plan: pro, product_id: 42)." } ] ___SANDBOXED_JS_FOR_WEB_TEMPLATE___ var injectScript = require('injectScript'); var getCookieValues = require('getCookieValues'); var getUrl = require('getUrl'); var copyFromWindow = require('copyFromWindow'); var callInWindow = require('callInWindow'); var setInWindow = require('setInWindow'); var makeNumber = require('makeNumber'); var makeString = require('makeString'); var log = require('logToConsole'); var installationToken = data.installationToken; var eventId = data.eventId; var eventName = data.eventName; var rawValue = data.value; var currency = data.currency || 'USD'; var customDataRows = data.customData; // Build custom_data object from the table rows var customData = {}; if (customDataRows) { for (var i = 0; i < customDataRows.length; i++) { var row = customDataRows[i]; if (row.key) { customData[makeString(row.key)] = makeString(row.value); } } } // ── Attribution: read lkid from URL query string ────────────────────────── var clickId = null; var query = getUrl('query'); if (query) { var pairs = query.split('&'); for (var j = 0; j < pairs.length; j++) { var kv = pairs[j].split('='); if (kv[0] === 'lkid' && kv.length > 1) { clickId = kv[1]; break; } } } // Fallback: read lkid from first-party cookie set by the pixel SDK if (!clickId) { var cookieVals = getCookieValues('lk_click_id'); if (cookieVals && cookieVals.length > 0) { clickId = cookieVals[0]; } } log('[Linkube] event:', eventName, '| has_lkid:', !!clickId); // ── Fire the conversion event ───────────────────────────────────────────── function doTrack() { var opts = { event_id: eventId, currency: currency, custom_data: customData }; if (rawValue !== undefined && rawValue !== '') { opts.value = makeNumber(rawValue); } if (clickId) { opts.click_id = clickId; } callInWindow('linkube.track', eventName, opts); data.gtmOnSuccess(); } // ── Load the Linkube pixel SDK if not yet present ───────────────────────── // Pre-set the publishable token so the injected pixel binds ingestion to one workspace. setInWindow('_lk_token', installationToken, true); var sdkLoaded = copyFromWindow('linkube') && copyFromWindow('linkube.track'); if (sdkLoaded) { // SDK already on the page (e.g. standalone