@adv-re/segment-wrapper 4.36.2 → 5.0.0-beta.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/index.mjs CHANGED
@@ -98,237 +98,6 @@ var getAdobeMCVisitorID = async () => {
98
98
  return getConfig("importAdobeVisitorId") === true ? importVisitorApiAndGetAdobeMCVisitorID() : getAdobeMarketingCloudVisitorIdFromWindow();
99
99
  };
100
100
 
101
- // src/events.ts
102
- var EVENTS = {
103
- GA4_INIT_EVENT_SENT: "ga4InitEventSent"
104
- };
105
-
106
- // src/middlewares/source/pageReferrer.ts
107
- var referrerState = {
108
- spaReferrer: "",
109
- referrer: ""
110
- };
111
- var utils = {
112
- /**
113
- * @returns The referrer of the document
114
- */
115
- getDocumentReferrer: () => document.referrer,
116
- /**
117
- * @returns The actual location with protocol, domain and pathname
118
- */
119
- getActualLocation: () => {
120
- const { origin, pathname } = window.location;
121
- return `${origin}${pathname}`;
122
- },
123
- /**
124
- * @returns The actual query string
125
- */
126
- getActualQueryString: () => {
127
- const { search } = window.location;
128
- return search;
129
- }
130
- };
131
- var getPageReferrer = ({ isPageTrack = false } = {}) => {
132
- const { referrer, spaReferrer } = referrerState;
133
- const referrerToUse = isPageTrack ? referrer : spaReferrer;
134
- return referrerToUse || utils.getDocumentReferrer();
135
- };
136
- var updatePageReferrer = () => {
137
- referrerState.spaReferrer = getPageReferrer({ isPageTrack: true });
138
- referrerState.referrer = utils.getActualLocation();
139
- };
140
- var pageReferrer = ({ payload, next }) => {
141
- const {
142
- obj: { context }
143
- } = payload;
144
- const { isPageTrack } = context;
145
- const referrer = getPageReferrer({ isPageTrack });
146
- payload.obj.context = {
147
- ...context,
148
- page: {
149
- ...context.page,
150
- referrer
151
- }
152
- };
153
- if (isPageTrack) {
154
- updatePageReferrer();
155
- }
156
- next(payload);
157
- };
158
-
159
- // src/repositories/googleRepository.ts
160
- var FIELDS = {
161
- clientId: "client_id",
162
- sessionId: "session_id"
163
- };
164
- var DEFAULT_DATA_LAYER_NAME = "dataLayer";
165
- var CONSENT_STATES = {
166
- granted: "granted",
167
- denied: "denied"
168
- };
169
- var CONSENT_STATE_GRANTED_VALUE = 1;
170
- var CONSENT_STATE_DENIED_VALUE = 2;
171
- var STC = {
172
- QUERY: "stc",
173
- SPLIT_SYMBOL: "-",
174
- CAMPAIGN_SPLIT_SYMBOL: ":"
175
- };
176
- var UTM_CAMPAIGN = "utm_campaign";
177
- var UTM_MEDIUM = "utm_medium";
178
- var UTM_SOURCE = "utm_source";
179
- var UTM_CONTENT = "utm_content";
180
- var UTM_CAMPAIGN_ID = "utm_id";
181
- var UTM_TERM = "utm_term";
182
- var STC_MEDIUM_TRANSFORMATIONS = {
183
- aff: "affiliate",
184
- dis: "display",
185
- em: "email",
186
- met: "paid-metasearch",
187
- sem: "paid-search",
188
- rt: "display",
189
- sm: "social-media",
190
- sp: "paid-social",
191
- pn: "push-notification",
192
- cs: "cross-sites"
193
- };
194
- var STC_INVALID_CONTENT = "na";
195
- var DEFAULT_GA_INIT_EVENT = "sui";
196
- var EMPTY_STC = { medium: null, source: null, campaign: null };
197
- var loadScript = async (src) => new Promise(function(resolve, reject) {
198
- const script = document.createElement("script");
199
- script.src = src;
200
- script.onload = () => resolve();
201
- script.onerror = reject;
202
- document.head.appendChild(script);
203
- });
204
- var loadGoogleAnalytics = async () => {
205
- const googleAnalyticsMeasurementId = getConfig("googleAnalyticsMeasurementId");
206
- const dataLayerName = getConfig("googleAnalyticsDataLayer") || DEFAULT_DATA_LAYER_NAME;
207
- if (!googleAnalyticsMeasurementId) return Promise.resolve(false);
208
- const gtagScript = `https://www.googletagmanager.com/gtag/js?id=${googleAnalyticsMeasurementId}&l=${dataLayerName}`;
209
- return loadScript(gtagScript).then(() => true);
210
- };
211
- var triggerGoogleAnalyticsInitEvent = (sessionId) => {
212
- const eventName = getConfig("googleAnalyticsInitEvent") ?? DEFAULT_GA_INIT_EVENT;
213
- const eventPrefix = `ga_event_${eventName}_`;
214
- const eventKey = `${eventPrefix}${sessionId}`;
215
- if (typeof window.gtag === "undefined") return;
216
- if (!localStorage.getItem(eventKey)) {
217
- window.gtag("event", eventName);
218
- console.log(`Sending GA4 event "${eventName}" for the session "${sessionId}"`);
219
- localStorage.setItem(eventKey, "true");
220
- if (typeof window.dispatchEvent === "function") {
221
- const event = new CustomEvent(EVENTS.GA4_INIT_EVENT_SENT, {
222
- detail: { eventName, sessionId }
223
- });
224
- window.dispatchEvent(event);
225
- }
226
- }
227
- Object.keys(localStorage).forEach((key) => {
228
- if (key.startsWith(eventPrefix) && key !== eventKey) {
229
- localStorage.removeItem(key);
230
- }
231
- });
232
- };
233
- var getGoogleField = async (field) => {
234
- const googleAnalyticsMeasurementId = getConfig("googleAnalyticsMeasurementId");
235
- if (!googleAnalyticsMeasurementId) return Promise.resolve(void 0);
236
- return new Promise((resolve) => {
237
- window.gtag?.("get", googleAnalyticsMeasurementId, field, resolve);
238
- });
239
- };
240
- var trackingTagsTypes = {
241
- STC: "stc",
242
- UTM: "utm"
243
- };
244
- var getCampaignDetails = ({ needsTransformation = true } = {}) => {
245
- const { medium, source, campaign, content, term } = readQueryParams();
246
- if (!medium || !source || !campaign) return null;
247
- const [id, name] = campaign.split(STC.CAMPAIGN_SPLIT_SYMBOL);
248
- if (!id && !name) return null;
249
- const needsContent = typeof content !== "undefined" && content !== STC_INVALID_CONTENT;
250
- return {
251
- campaign: {
252
- medium: needsTransformation && STC_MEDIUM_TRANSFORMATIONS[medium] || medium,
253
- ...typeof name !== "undefined" && { id },
254
- name: name ?? id,
255
- source,
256
- ...needsContent && { content },
257
- ...typeof term !== "undefined" && { term }
258
- }
259
- };
260
- };
261
- function readQueryParams() {
262
- const search = utils.getActualQueryString();
263
- const searchParams = new URLSearchParams(search);
264
- return getConfig("trackingTagsType") === trackingTagsTypes.UTM ? readFromUtm(searchParams) : readFromStc(searchParams);
265
- }
266
- function readFromStc(searchParams) {
267
- if (!hasStc(searchParams)) return EMPTY_STC;
268
- const stc = searchParams.get(STC.QUERY);
269
- const [medium, source, campaign, content, term] = stc?.split(STC.SPLIT_SYMBOL) || [];
270
- return { medium, source, campaign, content, term };
271
- }
272
- function hasStc(searchParams) {
273
- return searchParams.has(STC.QUERY);
274
- }
275
- function readFromUtm(searchParams) {
276
- const campaignId = searchParams.get(UTM_CAMPAIGN_ID);
277
- const campaignName = searchParams.get(UTM_CAMPAIGN);
278
- const medium = searchParams.get(UTM_MEDIUM);
279
- const source = searchParams.get(UTM_SOURCE);
280
- const content = searchParams.get(UTM_CONTENT);
281
- const term = searchParams.get(UTM_TERM);
282
- const campaign = campaignId ? `${campaignId}${STC.CAMPAIGN_SPLIT_SYMBOL}${campaignName}` : campaignName;
283
- const missingAnyMandatoryFields = !medium || !source || !campaign;
284
- if (missingAnyMandatoryFields && hasStc(searchParams)) {
285
- return readFromStc(searchParams);
286
- }
287
- return {
288
- campaign,
289
- medium,
290
- source,
291
- content: content ?? void 0,
292
- term: term ?? void 0
293
- };
294
- }
295
- var getGoogleClientId = async () => getGoogleField(FIELDS.clientId);
296
- var getGoogleSessionId = async () => {
297
- const sessionId = await getGoogleField(FIELDS.sessionId);
298
- if (sessionId) {
299
- triggerGoogleAnalyticsInitEvent(sessionId);
300
- }
301
- return sessionId;
302
- };
303
- function getGoogleConsentValue(consentType = "analytics_storage") {
304
- try {
305
- const value = window.google_tag_data?.ics?.getConsentState?.(consentType);
306
- if (value === CONSENT_STATE_GRANTED_VALUE) return CONSENT_STATES.granted;
307
- if (value === CONSENT_STATE_DENIED_VALUE) return CONSENT_STATES.denied;
308
- return void 0;
309
- } catch {
310
- return void 0;
311
- }
312
- }
313
- var getConsentState = () => getGoogleConsentValue() ?? CONSENT_STATES.denied;
314
- var setGoogleUserId = (userId) => {
315
- const googleAnalyticsMeasurementId = getConfig("googleAnalyticsMeasurementId");
316
- if (!googleAnalyticsMeasurementId || !userId) return;
317
- window.gtag?.("set", "user_id", userId);
318
- };
319
- var sendGoogleConsents = (mode = "default", consents) => {
320
- window.gtag?.(
321
- "consent",
322
- mode,
323
- consents || {
324
- analytics_storage: CONSENT_STATES.denied,
325
- ad_user_data: CONSENT_STATES.denied,
326
- ad_personalization: CONSENT_STATES.denied,
327
- ad_storage: CONSENT_STATES.denied
328
- }
329
- );
330
- };
331
-
332
101
  // src/tcf.ts
333
102
  var TCF_COOKIE_KEY = "borosTcf";
334
103
  var TCF_API_VERSION = 2;
@@ -382,17 +151,30 @@ var checkTcfIsAvailable = () => {
382
151
  };
383
152
  var checkHasUserConsentedAnalytics = (userConsents) => NEEDED_PURPOSES.analytics.every((purposeId) => userConsents[`${purposeId}`]);
384
153
  var checkHasUserConsentedAdvertising = (userConsents) => NEEDED_PURPOSES.advertising.every((purposeId) => userConsents[`${purposeId}`]);
385
- var trackTcf = ({ gdprPrivacy }) => segmentWrapper_default.track(
386
- CMP_TRACK_EVENT,
387
- {
388
- ...TCF_TRACK_PROPERTIES,
389
- ...getConfig("tcfTrackDefaultProperties") || {}
390
- },
391
- {
392
- gdpr_privacy: gdprPrivacy.analytics,
393
- gdpr_privacy_advertising: gdprPrivacy.advertising
394
- }
395
- );
154
+ var trackTcf = ({ gdprPrivacy }) => {
155
+ const isAnalyticsAccepted = gdprPrivacy.analytics === USER_GDPR.ACCEPTED;
156
+ const isAdvertisingAccepted = gdprPrivacy.advertising === USER_GDPR.ACCEPTED;
157
+ return segmentWrapper_default.track(
158
+ CMP_TRACK_EVENT,
159
+ {
160
+ ...TCF_TRACK_PROPERTIES,
161
+ ...getConfig("tcfTrackDefaultProperties") || {}
162
+ },
163
+ {
164
+ // Consent Mode properties for Segment → GA4 mapping (v5)
165
+ // These are sent as event properties and mapped in Segment GA4 Device Mode to GA4 Consent Mode
166
+ google_consents: {
167
+ analytics_storage: isAnalyticsAccepted ? "granted" : "denied",
168
+ ad_storage: isAdvertisingAccepted ? "granted" : "denied",
169
+ ad_user_data: isAdvertisingAccepted ? "granted" : "denied",
170
+ ad_personalization: isAdvertisingAccepted ? "granted" : "denied"
171
+ },
172
+ // Keep gdpr_privacy in context for compatibility with other integrations
173
+ gdpr_privacy: gdprPrivacy.analytics,
174
+ gdpr_privacy_advertising: gdprPrivacy.advertising
175
+ }
176
+ );
177
+ };
396
178
  var getGdprPrivacyValue = () => {
397
179
  const gdprPrivacyValue = gdprState.get();
398
180
  if (gdprPrivacyValue !== void 0) return Promise.resolve(gdprPrivacyValue);
@@ -400,6 +182,9 @@ var getGdprPrivacyValue = () => {
400
182
  gdprState.addListener((gdprPrivacyValue2) => resolve(gdprPrivacyValue2));
401
183
  });
402
184
  };
185
+ var getGdprPrivacyValueSync = () => {
186
+ return gdprState.get();
187
+ };
403
188
  var checkAnalyticsGdprIsAccepted = (gdprPrivacyValue) => {
404
189
  return gdprPrivacyValue?.analytics === USER_GDPR.ACCEPTED;
405
190
  };
@@ -462,11 +247,7 @@ function initTcfTracking() {
462
247
  analytics: analyticsStateKey,
463
248
  advertising: advertisingStateKey
464
249
  };
465
- const MIGRATION_DIDOMI_SEGMENT_WRAPPER_FLAG = "didomi-migration";
466
- const isDidomiMigration = isClient && window.sessionStorage.getItem(MIGRATION_DIDOMI_SEGMENT_WRAPPER_FLAG);
467
- return !isDidomiMigration && trackTcf({
468
- gdprPrivacy
469
- });
250
+ trackTcf({ gdprPrivacy });
470
251
  }
471
252
  }
472
253
  });
@@ -574,14 +355,10 @@ var getTrackIntegrations = async ({
574
355
  }) => {
575
356
  const isGdprAccepted = checkAnalyticsGdprIsAccepted(gdprPrivacyValue);
576
357
  let marketingCloudVisitorId;
577
- let sessionId;
578
- let clientId;
579
358
  try {
580
359
  if (isGdprAccepted) {
581
360
  marketingCloudVisitorId = await getAdobeMCVisitorID();
582
361
  }
583
- sessionId = await getGoogleSessionId();
584
- clientId = await getGoogleClientId();
585
362
  } catch (error) {
586
363
  console.error(error);
587
364
  }
@@ -589,10 +366,7 @@ var getTrackIntegrations = async ({
589
366
  return {
590
367
  ...restOfIntegrations,
591
368
  "Adobe Analytics": marketingCloudVisitorId ? { marketingCloudVisitorId } : true,
592
- "Google Analytics 4": clientId && sessionId ? {
593
- clientId,
594
- sessionId
595
- } : true
369
+ "Google Analytics 4 Web": true
596
370
  };
597
371
  };
598
372
  var getRestOfIntegrations = ({
@@ -631,9 +405,6 @@ var getExternalIds = ({
631
405
  );
632
406
  return { externalIds: uniqueExternalIds };
633
407
  };
634
- var getConsentValue = (gdprValue) => {
635
- return gdprValue === USER_GDPR.ACCEPTED ? CONSENT_STATES.granted : CONSENT_STATES.denied;
636
- };
637
408
  var decorateContextWithNeededData = async ({
638
409
  event = "",
639
410
  context = {}
@@ -645,10 +416,6 @@ var decorateContextWithNeededData = async ({
645
416
  getTrackIntegrations({ gdprPrivacyValue, event }),
646
417
  getXandrId({ gdprPrivacyValueAdvertising })
647
418
  ]);
648
- const analyticsConsentValue = getGoogleConsentValue("analytics_storage") ?? getConsentValue(gdprPrivacyValueAnalytics);
649
- const adUserDataConsentValue = getGoogleConsentValue("ad_user_data") ?? getConsentValue(gdprPrivacyValueAdvertising);
650
- const adPersonalizationConsentValue = getGoogleConsentValue("ad_personalization") ?? getConsentValue(gdprPrivacyValueAdvertising);
651
- const adStorageConsentValue = getGoogleConsentValue("ad_storage") ?? getConsentValue(gdprPrivacyValueAdvertising);
652
419
  if (!isGdprAccepted) {
653
420
  context.integrations = {
654
421
  ...context.integrations ?? {},
@@ -657,21 +424,13 @@ var decorateContextWithNeededData = async ({
657
424
  Webhook: true
658
425
  };
659
426
  }
660
- const google_consents = {
661
- analytics_storage: analyticsConsentValue,
662
- ad_user_data: adUserDataConsentValue,
663
- ad_personalization: adPersonalizationConsentValue,
664
- ad_storage: adStorageConsentValue
665
- };
666
427
  return {
667
428
  ...context,
668
429
  ...!isGdprAccepted && { ip: "0.0.0.0" },
669
430
  ...getExternalIds({ context, xandrId }),
670
- analytics_storage: getConsentState(),
671
- clientVersion: `segment-wrapper@${"4.36.2"}`,
431
+ clientVersion: `segment-wrapper@${"5.0.0-beta.1"}`,
672
432
  gdpr_privacy: gdprPrivacyValueAnalytics,
673
433
  gdpr_privacy_advertising: gdprPrivacyValueAdvertising,
674
- google_consents,
675
434
  integrations: {
676
435
  ...context.integrations,
677
436
  ...integrations
@@ -697,10 +456,6 @@ var track = (event, properties, context = {}, callback) => new Promise((resolve)
697
456
  resolve();
698
457
  }
699
458
  };
700
- const needsConsentManagement = getConfig("googleAnalyticsConsentManagement");
701
- if (needsConsentManagement && event === CMP_TRACK_EVENT) {
702
- sendGoogleConsents("update", newContext.google_consents);
703
- }
704
459
  window.analytics.track(
705
460
  event,
706
461
  newProperties,
@@ -720,7 +475,6 @@ var track = (event, properties, context = {}, callback) => new Promise((resolve)
720
475
  var identify = async (userIdParam, traits, options, callback) => {
721
476
  const gdprPrivacyValue = await getGdprPrivacyValue();
722
477
  const userId = getUserId(userIdParam);
723
- setGoogleUserId(userId);
724
478
  return window.analytics.identify(
725
479
  userId,
726
480
  checkAnalyticsGdprIsAccepted(gdprPrivacyValue) ? traits : {},
@@ -764,14 +518,166 @@ if (isClient) {
764
518
  }
765
519
  }
766
520
 
521
+ // src/middlewares/source/pageReferrer.ts
522
+ var referrerState = {
523
+ spaReferrer: "",
524
+ referrer: ""
525
+ };
526
+ var utils = {
527
+ /**
528
+ * @returns The referrer of the document
529
+ */
530
+ getDocumentReferrer: () => document.referrer,
531
+ /**
532
+ * @returns The actual location with protocol, domain and pathname
533
+ */
534
+ getActualLocation: () => {
535
+ const { origin, pathname } = window.location;
536
+ return `${origin}${pathname}`;
537
+ },
538
+ /**
539
+ * @returns The actual query string
540
+ */
541
+ getActualQueryString: () => {
542
+ const { search } = window.location;
543
+ return search;
544
+ }
545
+ };
546
+ var getPageReferrer = ({ isPageTrack = false } = {}) => {
547
+ const { referrer, spaReferrer } = referrerState;
548
+ const referrerToUse = isPageTrack ? referrer : spaReferrer;
549
+ return referrerToUse || utils.getDocumentReferrer();
550
+ };
551
+ var updatePageReferrer = () => {
552
+ referrerState.spaReferrer = getPageReferrer({ isPageTrack: true });
553
+ referrerState.referrer = utils.getActualLocation();
554
+ };
555
+ var pageReferrer = ({ payload, next }) => {
556
+ const {
557
+ obj: { context }
558
+ } = payload;
559
+ const { isPageTrack } = context;
560
+ const referrer = getPageReferrer({ isPageTrack });
561
+ payload.obj.context = {
562
+ ...context,
563
+ page: {
564
+ ...context.page,
565
+ referrer
566
+ }
567
+ };
568
+ if (isPageTrack) {
569
+ updatePageReferrer();
570
+ }
571
+ next(payload);
572
+ };
573
+
574
+ // src/repositories/googleRepository.ts
575
+ var STC = {
576
+ QUERY: "stc",
577
+ SPLIT_SYMBOL: "-",
578
+ CAMPAIGN_SPLIT_SYMBOL: ":"
579
+ };
580
+ var UTM_CAMPAIGN = "utm_campaign";
581
+ var UTM_MEDIUM = "utm_medium";
582
+ var UTM_SOURCE = "utm_source";
583
+ var UTM_CONTENT = "utm_content";
584
+ var UTM_CAMPAIGN_ID = "utm_id";
585
+ var UTM_TERM = "utm_term";
586
+ var STC_MEDIUM_TRANSFORMATIONS = {
587
+ aff: "affiliate",
588
+ dis: "display",
589
+ em: "email",
590
+ met: "paid-metasearch",
591
+ sem: "paid-search",
592
+ rt: "display",
593
+ sm: "social-media",
594
+ sp: "paid-social",
595
+ pn: "push-notification",
596
+ cs: "cross-sites"
597
+ };
598
+ var STC_INVALID_CONTENT = "na";
599
+ var EMPTY_STC = { medium: null, source: null, campaign: null };
600
+ var trackingTagsTypes = {
601
+ STC: "stc",
602
+ UTM: "utm"
603
+ };
604
+ var getCampaignDetails = ({ needsTransformation = true } = {}) => {
605
+ const { medium, source, campaign, content, term } = readQueryParams();
606
+ if (!medium || !source || !campaign) return null;
607
+ const [id, name] = campaign.split(STC.CAMPAIGN_SPLIT_SYMBOL);
608
+ if (!id && !name) return null;
609
+ const needsContent = typeof content !== "undefined" && content !== STC_INVALID_CONTENT;
610
+ return {
611
+ campaign: {
612
+ medium: needsTransformation && STC_MEDIUM_TRANSFORMATIONS[medium] || medium,
613
+ ...typeof name !== "undefined" && { id },
614
+ name: name ?? id,
615
+ source,
616
+ ...needsContent && { content },
617
+ ...typeof term !== "undefined" && { term }
618
+ }
619
+ };
620
+ };
621
+ function readQueryParams() {
622
+ const search = utils.getActualQueryString();
623
+ const searchParams = new URLSearchParams(search);
624
+ return getConfig("trackingTagsType") === trackingTagsTypes.UTM ? readFromUtm(searchParams) : readFromStc(searchParams);
625
+ }
626
+ function readFromStc(searchParams) {
627
+ if (!hasStc(searchParams)) return EMPTY_STC;
628
+ const stc = searchParams.get(STC.QUERY);
629
+ const [medium, source, campaign, content, term] = stc?.split(STC.SPLIT_SYMBOL) || [];
630
+ return { medium, source, campaign, content, term };
631
+ }
632
+ function hasStc(searchParams) {
633
+ return searchParams.has(STC.QUERY);
634
+ }
635
+ function readFromUtm(searchParams) {
636
+ const campaignId = searchParams.get(UTM_CAMPAIGN_ID);
637
+ const campaignName = searchParams.get(UTM_CAMPAIGN);
638
+ const medium = searchParams.get(UTM_MEDIUM);
639
+ const source = searchParams.get(UTM_SOURCE);
640
+ const content = searchParams.get(UTM_CONTENT);
641
+ const term = searchParams.get(UTM_TERM);
642
+ const campaign = campaignId ? `${campaignId}${STC.CAMPAIGN_SPLIT_SYMBOL}${campaignName}` : campaignName;
643
+ const missingAnyMandatoryFields = !medium || !source || !campaign;
644
+ if (missingAnyMandatoryFields && hasStc(searchParams)) {
645
+ return readFromStc(searchParams);
646
+ }
647
+ return {
648
+ campaign,
649
+ medium,
650
+ source,
651
+ content: content ?? void 0,
652
+ term: term ?? void 0
653
+ };
654
+ }
655
+
767
656
  // src/middlewares/source/campaignContext.ts
768
657
  var campaignContext = ({ payload, next }) => {
769
- const googleAnalyticsMeasurementId = getConfig("googleAnalyticsMeasurementId");
770
- if (googleAnalyticsMeasurementId) {
771
- const campaignDetails = getCampaignDetails();
658
+ const campaignDetails = getCampaignDetails();
659
+ payload.obj.context = {
660
+ ...payload.obj.context,
661
+ ...campaignDetails
662
+ };
663
+ next(payload);
664
+ };
665
+
666
+ // src/middlewares/source/consentMode.ts
667
+ var consentMode = ({ payload, next }) => {
668
+ const gdprPrivacyValue = getGdprPrivacyValueSync();
669
+ if (gdprPrivacyValue) {
670
+ const { analytics, advertising } = gdprPrivacyValue;
671
+ const isAnalyticsAccepted = analytics === USER_GDPR.ACCEPTED;
672
+ const isAdvertisingAccepted = advertising === USER_GDPR.ACCEPTED;
772
673
  payload.obj.context = {
773
674
  ...payload.obj.context,
774
- ...campaignDetails
675
+ google_consents: {
676
+ analytics_storage: isAnalyticsAccepted ? "granted" : "denied",
677
+ ad_storage: isAdvertisingAccepted ? "granted" : "denied",
678
+ ad_user_data: isAdvertisingAccepted ? "granted" : "denied",
679
+ ad_personalization: isAdvertisingAccepted ? "granted" : "denied"
680
+ }
775
681
  };
776
682
  }
777
683
  next(payload);
@@ -1001,6 +907,11 @@ var TCFEvents = /* @__PURE__ */ ((TCFEvents2) => {
1001
907
  return TCFEvents2;
1002
908
  })(TCFEvents || {});
1003
909
 
910
+ // src/events.ts
911
+ var EVENTS = {
912
+ GA4_INIT_EVENT_SENT: "ga4InitEventSent"
913
+ };
914
+
1004
915
  // src/utils/storage.ts
1005
916
  var storage = ({
1006
917
  type = "localStorage",
@@ -1058,6 +969,7 @@ var addMiddlewares = () => {
1058
969
  const experimentalPageDataMiddleware = getConfig("experimentalPageDataMiddleware");
1059
970
  window.analytics.addSourceMiddleware?.(userTraits);
1060
971
  window.analytics.addSourceMiddleware?.(defaultContextProperties);
972
+ window.analytics.addSourceMiddleware?.(consentMode);
1061
973
  window.analytics.addSourceMiddleware?.(campaignContext);
1062
974
  window.analytics.addSourceMiddleware?.(userScreenInfo);
1063
975
  window.analytics.addSourceMiddleware?.(pageReferrer);
@@ -1066,36 +978,11 @@ var addMiddlewares = () => {
1066
978
  }
1067
979
  };
1068
980
  if (isClient && window.analytics) {
1069
- const googleAnalyticsMeasurementId = getConfig("googleAnalyticsMeasurementId");
1070
- const dataLayerName = getConfig("googleAnalyticsDataLayer") || DEFAULT_DATA_LAYER_NAME;
1071
- const needsConsentManagement = getConfig("googleAnalyticsConsentManagement");
1072
- if (googleAnalyticsMeasurementId) {
1073
- const googleAnalyticsConfig = getConfig("googleAnalyticsConfig");
1074
- window[dataLayerName] = window[dataLayerName] || [];
1075
- window.gtag = window.gtag || function gtag() {
1076
- ;
1077
- window[dataLayerName].push(arguments);
1078
- };
1079
- window.gtag("js", /* @__PURE__ */ new Date());
1080
- if (needsConsentManagement) {
1081
- sendGoogleConsents();
1082
- }
1083
- window.gtag("config", googleAnalyticsMeasurementId, {
1084
- cookie_prefix: "segment",
1085
- send_page_view: false,
1086
- ...googleAnalyticsConfig,
1087
- ...getCampaignDetails()
1088
- });
1089
- loadGoogleAnalytics().catch((error) => {
1090
- console.error("[segment-wrapper] Failed to load Google Analytics", error);
1091
- });
1092
- }
1093
981
  window.analytics.ready(checkAnonymousId);
1094
982
  window.analytics.addSourceMiddleware ? addMiddlewares() : window.analytics.ready(addMiddlewares);
1095
983
  }
1096
984
  var index_default = segmentWrapper_default;
1097
985
  export {
1098
- CONSENT_STATES,
1099
986
  EVENTS,
1100
987
  TCFEvents,
1101
988
  UserGDPR,
@@ -1105,6 +992,7 @@ export {
1105
992
  index_default as default,
1106
993
  getAdobeMCVisitorID,
1107
994
  getAdobeVisitorData,
995
+ getCampaignDetails,
1108
996
  getConfig,
1109
997
  getStorageItem,
1110
998
  getUniversalId,
@@ -1119,5 +1007,6 @@ export {
1119
1007
  setConfig,
1120
1008
  setStorageItem,
1121
1009
  storage,
1122
- toCookieDomain
1010
+ toCookieDomain,
1011
+ trackingTagsTypes
1123
1012
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adv-re/segment-wrapper",
3
- "version": "4.36.2",
3
+ "version": "5.0.0-beta.1",
4
4
  "description": "Modern TypeScript abstraction layer on top of the Segment library",
5
5
  "sideEffects": [
6
6
  "./src/utils/patchAnalytics.ts",
@@ -63,4 +63,4 @@
63
63
  },
64
64
  "author": "",
65
65
  "license": "ISC"
66
- }
66
+ }