@datalyr/web 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/datalyr.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @datalyr/web v1.0.0
2
+ * @datalyr/web v1.0.1
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2025 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -810,9 +810,36 @@ var Datalyr = (function () {
810
810
  class AttributionManager {
811
811
  constructor(options = {}) {
812
812
  this.UTM_PARAMS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
813
- this.CLICK_IDS = ['fbclid', 'gclid', 'ttclid', 'msclkid', 'twclid', 'li_fat_id', 'sclid', 'dclid', 'epik'];
813
+ // Updated to match dl.js - includes ALL ad platform click IDs
814
+ this.CLICK_IDS = [
815
+ 'fbclid', // Facebook/Meta
816
+ 'gclid', // Google Ads
817
+ 'gbraid', // Google Ads (iOS)
818
+ 'wbraid', // Google Ads (web)
819
+ 'ttclid', // TikTok
820
+ 'msclkid', // Microsoft/Bing
821
+ 'twclid', // Twitter/X
822
+ 'li_fat_id', // LinkedIn
823
+ 'sclid', // Snapchat
824
+ 'dclid', // Google Display/DoubleClick
825
+ 'epik', // Pinterest
826
+ 'rdt_cid', // Reddit
827
+ 'obclid', // Outbrain
828
+ 'irclid', // Impact Radius
829
+ 'ko_click_id' // Klaviyo
830
+ ];
831
+ // Default tracked params matching dl.js
832
+ this.DEFAULT_TRACKED_PARAMS = [
833
+ 'lyr', // Datalyr partner tracking
834
+ 'ref', // Generic referral
835
+ 'source', // Generic source (non-UTM)
836
+ 'campaign', // Generic campaign (non-UTM)
837
+ 'medium', // Generic medium (non-UTM)
838
+ 'gad_source' // Google Ads source parameter
839
+ ];
814
840
  this.attributionWindow = options.attributionWindow || 30 * 24 * 60 * 60 * 1000; // 30 days
815
- this.trackedParams = options.trackedParams || [];
841
+ // Merge default tracked params with user-provided ones
842
+ this.trackedParams = [...this.DEFAULT_TRACKED_PARAMS, ...(options.trackedParams || [])];
816
843
  }
817
844
  /**
818
845
  * Capture current attribution from URL
@@ -899,9 +926,9 @@ var Datalyr = (function () {
899
926
  const touchpoint = {
900
927
  timestamp: Date.now(),
901
928
  sessionId,
902
- source: attribution.source,
903
- medium: attribution.medium,
904
- campaign: attribution.campaign
929
+ source: attribution.source || undefined,
930
+ medium: attribution.medium || undefined,
931
+ campaign: attribution.campaign || undefined
905
932
  };
906
933
  journey.push(touchpoint);
907
934
  // Keep last 30 touchpoints
@@ -1073,7 +1100,6 @@ var Datalyr = (function () {
1073
1100
  this.recentEventIds = new Set();
1074
1101
  this.MAX_RECENT_EVENT_IDS = 1000;
1075
1102
  this.OFFLINE_QUEUE_KEY = 'dl_offline_queue';
1076
- this.currentEndpointIndex = 0;
1077
1103
  this.config = {
1078
1104
  batchSize: config.batchSize || 10,
1079
1105
  flushInterval: config.flushInterval || 5000,
@@ -1134,7 +1160,10 @@ var Datalyr = (function () {
1134
1160
  const toDelete = this.recentEventIds.size - this.MAX_RECENT_EVENT_IDS;
1135
1161
  const iterator = this.recentEventIds.values();
1136
1162
  for (let i = 0; i < toDelete; i++) {
1137
- this.recentEventIds.delete(iterator.next().value);
1163
+ const next = iterator.next();
1164
+ if (!next.done) {
1165
+ this.recentEventIds.delete(next.value);
1166
+ }
1138
1167
  }
1139
1168
  }
1140
1169
  return false;
@@ -1245,7 +1274,6 @@ var Datalyr = (function () {
1245
1274
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
1246
1275
  }
1247
1276
  this.log(`Batch sent successfully to ${currentEndpoint}: ${events.length} events`);
1248
- this.currentEndpointIndex = 0; // Reset to primary on success
1249
1277
  }
1250
1278
  catch (error) {
1251
1279
  // Try next fallback endpoint if available
@@ -2059,8 +2087,8 @@ var Datalyr = (function () {
2059
2087
  document.head.appendChild(script);
2060
2088
  // Initialize gtag
2061
2089
  window.dataLayer = window.dataLayer || [];
2062
- function gtag() {
2063
- window.dataLayer.push(arguments);
2090
+ function gtag(...args) {
2091
+ window.dataLayer.push(args);
2064
2092
  }
2065
2093
  window.gtag = gtag;
2066
2094
  gtag('js', new Date());
@@ -2079,7 +2107,7 @@ var Datalyr = (function () {
2079
2107
  initializeTikTokPixel(config) {
2080
2108
  try {
2081
2109
  // Load TikTok Pixel script
2082
- (function (w, d, t) {
2110
+ (function (w, _d, t) {
2083
2111
  w.TiktokAnalyticsObject = t;
2084
2112
  var ttq = w[t] = w[t] || [];
2085
2113
  ttq.methods = ['page', 'track', 'identify', 'instances', 'debug', 'on', 'off', 'once', 'ready', 'alias', 'group', 'enableCookie', 'disableCookie'];
@@ -2096,6 +2124,7 @@ var Datalyr = (function () {
2096
2124
  return e;
2097
2125
  };
2098
2126
  ttq.load = function (e, n) {
2127
+ var _a;
2099
2128
  var i = 'https://analytics.tiktok.com/i18n/pixel/events.js';
2100
2129
  ttq._i = ttq._i || {};
2101
2130
  ttq._i[e] = [];
@@ -2106,7 +2135,7 @@ var Datalyr = (function () {
2106
2135
  o.async = true;
2107
2136
  o.src = i + '?sdkid=' + e + '&lib=' + t;
2108
2137
  var a = document.getElementsByTagName('script')[0];
2109
- a.parentNode.insertBefore(o, a);
2138
+ (_a = a.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(o, a);
2110
2139
  };
2111
2140
  })(window, document, 'ttq');
2112
2141
  // Initialize pixel
@@ -2122,7 +2151,7 @@ var Datalyr = (function () {
2122
2151
  * Track event to all initialized pixels
2123
2152
  */
2124
2153
  trackToPixels(eventName, properties = {}) {
2125
- var _a, _b, _c, _d, _e, _f;
2154
+ var _a, _b, _c, _e, _f, _g;
2126
2155
  // Track to Meta Pixel
2127
2156
  if (((_b = (_a = this.pixels) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.enabled) && window.fbq) {
2128
2157
  try {
@@ -2133,7 +2162,7 @@ var Datalyr = (function () {
2133
2162
  }
2134
2163
  }
2135
2164
  // Track to Google Tag
2136
- if (((_d = (_c = this.pixels) === null || _c === void 0 ? void 0 : _c.google) === null || _d === void 0 ? void 0 : _d.enabled) && window.gtag) {
2165
+ if (((_e = (_c = this.pixels) === null || _c === void 0 ? void 0 : _c.google) === null || _e === void 0 ? void 0 : _e.enabled) && window.gtag) {
2137
2166
  try {
2138
2167
  window.gtag('event', eventName, properties);
2139
2168
  }
@@ -2142,7 +2171,7 @@ var Datalyr = (function () {
2142
2171
  }
2143
2172
  }
2144
2173
  // Track to TikTok Pixel
2145
- if (((_f = (_e = this.pixels) === null || _e === void 0 ? void 0 : _e.tiktok) === null || _f === void 0 ? void 0 : _f.enabled) && window.ttq) {
2174
+ if (((_g = (_f = this.pixels) === null || _f === void 0 ? void 0 : _f.tiktok) === null || _g === void 0 ? void 0 : _g.enabled) && window.ttq) {
2146
2175
  try {
2147
2176
  // Map common events to TikTok names
2148
2177
  const tiktokEventMap = {
@@ -2644,13 +2673,39 @@ var Datalyr = (function () {
2644
2673
  // Create payload with both camelCase and snake_case fields
2645
2674
  const identityFields = this.identity.getIdentityFields();
2646
2675
  const eventId = generateUUID();
2647
- const payload = Object.assign(Object.assign({
2676
+ // Ensure we have all required identity fields
2677
+ const distinctId = identityFields.distinct_id;
2678
+ const anonymousId = identityFields.anonymous_id;
2679
+ const visitorId = identityFields.visitor_id || anonymousId;
2680
+ const sessionId = identityFields.session_id;
2681
+ const payload = {
2648
2682
  // Required fields
2649
- workspaceId: this.config.workspaceId, workspace_id: this.config.workspaceId, eventId: eventId, event_id: eventId, // Snake case alias (same ID)
2650
- eventName, event_name: eventName, // Snake case alias
2651
- eventData, event_data: eventData, source: 'web', timestamp: new Date().toISOString() }, identityFields), {
2683
+ workspaceId: this.config.workspaceId,
2684
+ workspace_id: this.config.workspaceId, // Snake case alias
2685
+ eventId: eventId,
2686
+ event_id: eventId, // Snake case alias (same ID)
2687
+ eventName,
2688
+ event_name: eventName, // Snake case alias
2689
+ eventData,
2690
+ event_data: eventData, // Snake case alias
2691
+ source: 'web',
2692
+ timestamp: new Date().toISOString(),
2693
+ // Identity fields (explicit to satisfy TypeScript)
2694
+ distinct_id: distinctId,
2695
+ anonymous_id: anonymousId,
2696
+ visitor_id: visitorId,
2697
+ visitorId: visitorId,
2698
+ user_id: identityFields.user_id,
2699
+ canonical_id: identityFields.canonical_id,
2700
+ sessionId: sessionId,
2701
+ session_id: sessionId,
2702
+ // Resolution metadata
2703
+ resolution_method: 'browser_sdk',
2704
+ resolution_confidence: 1.0,
2652
2705
  // SDK metadata
2653
- sdk_version: '1.0.0', sdk_name: 'datalyr-web-sdk' });
2706
+ sdk_version: '1.0.0',
2707
+ sdk_name: 'datalyr-web-sdk'
2708
+ };
2654
2709
  return payload;
2655
2710
  }
2656
2711
  /**