Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions packages/sui-segment-wrapper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
# CHANGELOG

# 4.41.0 (2026-03-30)


### Features

* force bump ([605f536](https://github.com/SUI-Components/sui/commit/605f536a2667aec5230a0369a9a418ee660524a3))
* wait for GA4 cookie and use correct container when multiple exis ([b46b471](https://github.com/SUI-Components/sui/commit/b46b47153db14c340bd2b6e5f4a517a0a278642f))



# 4.40.0 (2026-03-30)


### Bug Fixes

* retrieve cookie value by measurement id ([ad91525](https://github.com/SUI-Components/sui/commit/ad9152567164f995d0e0d03f7a5a0ec010c65079))



# 4.39.0 (2026-03-30)


### Bug Fixes

* fix ga4 session id inconsistencies ([d6664f0](https://github.com/SUI-Components/sui/commit/d6664f079d099e8695199605f873bdd668f57df1))



# 4.38.0 (2026-03-18)


### Features

* force release ([a1f13f2](https://github.com/SUI-Components/sui/commit/a1f13f2d7439fd2453815ffa81036c8d291cd31b))



# 4.37.0 (2026-03-16)


### Bug Fixes

* improve session id assignment to all destinations ([dc3653c](https://github.com/SUI-Components/sui/commit/dc3653c48a55b6d2dc0652b94bcfae8f514f6115))


### Features

* prioritize GA4 cookie over API to fix session ID inconsistencies ([48b2186](https://github.com/SUI-Components/sui/commit/48b2186b1717fa57b7f734799e45634e548612cc))



# 4.36.0 (2025-12-04)


Expand Down
59 changes: 12 additions & 47 deletions packages/sui-segment-wrapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ This package adds an abstraction layer on top of [segment.com](https://segment.c

- [x] Add `page` method that internally uses `track` but with the correct `referrer` property.
- [x] Send `user.id` and `anonymousId` on every track.
- [x] Send anonymous data to AWS to be able to check data integrity with Adobe.

**Google Analytics 🔍**

- [x] Load GA4 if `googleAnalyticsMeasurementId` is provided.
- [x] Retrieve `clientId` and `sessionId` automatically from GA4 and put in Segment tracks.

**Adobe Marketing Cloud Visitor Id ☁️**

- [x] Load _Adobe Visitor API_ when needed (if flag `importAdobeVisitorId` is set to `true`, otherwise you should load `Visitor API` by your own to get the `mcvid`).
- [x] Fetch `marketingCloudVisitorId` and put in integrations object for every track.
- [x] Monkey patch `track` native Segment method to send `marketingCloudVisitorId` inside `context.integrations`.

**Consent Management Platform 🐾**

- [x] Automatic tracking of Consent Management Platform usage.
Expand Down Expand Up @@ -127,37 +120,15 @@ import analytics from '@s-ui/segment-wrapper'
</script>
```

### Step 3: Configure mandatory Segment Wrapper attributes:

The following configuration parameters are required and must be set for the system to function correctly:

- `ADOBE_ORG_ID`: This parameter is the Adobe Organization ID, required for integration with Adobe services. Please make sure that you replace the example value with your actual Adobe Org ID.
- `TRACKING_SERVER`: This specifies the tracking server URL that will be used for sending data and handling tracking requests.

These parameters need to be defined in the `window._SEGMENT_WRAPPER` object as follows:

```js
window.__SEGMENT_WRAPPER = {
ADOBE_ORG_ID: '012345678@AdobeOrg', // Mandatory!
TRACKING_SERVER: 'mycompany.test.net' // Mandatory!
}
```

Configure both values correctly before running the application to ensure proper tracking and data integration.

### Step 4: Configure Segment Wrapper (optional)
### Step 3: Configure Segment Wrapper (optional)

You could put a special config in a the `window.__mpi` to change some behaviour of the wrapper. This config MUST somewhere before using the Segment Wrapper.

- `googleAnalyticsMeasurementId`: _(optional)_ If set, this value will be used for the Google Analytics Measurement API. It will load `gtag` to get the client id.
- `googleAnalyticsConfig`: _(optional)_ If set, this config will be passed when initializing the Google Analytics Measurement API.
- `googleAnalyticsInitEvent`: _(optional)_ If set, an event will be sent in order to initialize all the Google Analytics data.
- `googleAnalyticsCookiePrefix`: _(optional)_ Cookie prefix for GA4 cookies. Defaults to `'segment'`. Example: if set to `'myprefix'`, will look for `myprefix_ga_<CONTAINER_ID>` cookies.
- `googleAnalyticsCookieTimeout`: _(optional)_ Maximum time in milliseconds to wait for GA4 cookie creation. Defaults to `5000` (5 seconds). Increase this value for slower networks or devices.
- `defaultContext`: _(optional)_ If set, properties will be merged and sent with every `track` and `page` in the **context object**. It's the ideal place to put the `site` and `vertical` info to make sure that static info will be sent along with all the tracking.
- `defaultProperties`: _(optional)_ If set, properties will be merged and sent with every `track` and `page`.
- `getCustomAdobeVisitorId`: _(optional)_ If set, the output of this function will be used as `marketingCloudVisitorId` in Adobe Analytics' integration. It must return a promise.
- `importAdobeVisitorId` _(optional)_ If set and `true`, Adobe Visitor API will be fetched from Segment Wrapper instead of relying on being loaded before from Tealium or other services. Right now, by default, this is `false` but in the next major this configuration will be `true` by default. If `getCustomAdobeVisitorId` is being used this will be ignored.
- `tcfTrackDefaultProperties` _(optional)_ If set, this property will be merged together with the default properties set to send with every tcf track event
- `universalId`: _(optional)_ If set this value will be used for the Visitor API and other services.
- `hashedUserEmail`: _(optional)_ If set and not `universalId` is set this value will be used for the Visitor API and other services.
Expand All @@ -168,25 +139,19 @@ You could put a special config in a the `window.__mpi` to change some behaviour
Example:

```js
window.__mpi = {
segmentWrapper: {
googleAnalyticsMeasurementId: 'G-XXXXXXXXXX',
googleAnalyticsCookiePrefix: 'segment', // optional, defaults to 'segment'
googleAnalyticsCookieTimeout: 5000, // optional, defaults to 5000ms (5 seconds)
universalId: '7ab9ddf3281d5d5458a29e8b3ae2864',
defaultContext: {
site: 'comprocasa',
vertical: 'realestate'
},
getCustomAdobeVisitorId: () => {
const visitorId = // get your visitorId
return Promise.resolve(visitorId)
},
tcfTrackDefaultProperties: {
tcfSpecialProp: 'anyvalue'
}
window.__mpi = {
segmentWrapper: {
googleAnalyticsMeasurementId: 'GA-123456789',
universalId: '7ab9ddf3281d5d5458a29e8b3ae2864',
defaultContext: {
site: 'comprocasa',
vertical: 'realestate'
},
tcfTrackDefaultProperties: {
tcfSpecialProp: 'anyvalue'
}
}
}
```

### It also provides additional information such as:
Expand Down
6 changes: 3 additions & 3 deletions packages/sui-segment-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@s-ui/segment-wrapper",
"version": "4.41.0",
"version": "4.36.0",
"description": "Abstraction layer on top of the Segment library.",
"main": "lib/index.js",
"license": "ISC",
Expand All @@ -9,9 +9,9 @@
"postlib": "npm run set:version",
"prepublishOnly": "npm run umd && npm run lib",
"set:version": "sed -i.bak \"s/process\\.env\\.VERSION/\\\"$npm_package_version\\\"/g\" lib/segmentWrapper.js && rm lib/segmentWrapper.js.bak",
"test": "npm run test:client",
"test:client": "VERSION=0.0.0 sui-test browser --src-pattern=src/index.js -H",
"test:client:watch": "VERSION=0.0.0 npm run test:client -- --watch",
"test:client": "VERSION=0.0.0 sui-test browser --src-pattern=src/index.js -H",
"test": "npm run test:client",
"test:umd": "npm run umd && npx servor ./umd",
"umd": "VERSION=$npm_package_version sui-bundler lib src-umd/index.js -o umd/ -p --root"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/sui-segment-wrapper/src-umd/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {getAdobeMCVisitorID, getAdobeVisitorData} from '../src/repositories/adobeRepository.js'
import analytics from '../src/index.js'
import analytics, {getAdobeMCVisitorID, getAdobeVisitorData} from '../src/index.js'

const w = window

Expand Down
9 changes: 7 additions & 2 deletions packages/sui-segment-wrapper/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ if (isClient && window.analytics) {
}

export default analytics
export {getGoogleClientId, getGoogleSessionId} from './repositories/googleRepository.js'
export {getUniversalId} from './universalId.js'
export {EVENTS} from './events.js'
export {getGoogleClientId, getGoogleSessionId} from './repositories/googleRepository.js'
export {getAdobeVisitorData, getAdobeMCVisitorID} from './repositories/adobeRepository.js'

// Deprecated Adobe Analytics functions - kept for backwards compatibility
// @deprecated Adobe Analytics integration has been removed
export const getAdobeVisitorData = () => Promise.resolve({trackingServer: '', version: ''})
// @deprecated Adobe Analytics integration has been removed
export const getAdobeMCVisitorID = () => Promise.resolve('')
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/**
* Capture document.referrer at module load time, before Safari ITP can clear it.
* This ensures the first page event has the real referrer from the external source.
*/
export const INITIAL_DOCUMENT_REFERRER = typeof document !== 'undefined' ? document.referrer : ''

/**
* Capture window.location.search at module load time, before Safari ITP can
* strip tracking parameters via redirects.
*/
export const INITIAL_SEARCH_STRING = typeof window !== 'undefined' ? window.location.search : ''

/**
* Capture initial URL at module load time
*/
const INITIAL_URL = typeof window !== 'undefined' ? window.location.href : ''

export const referrerState = {
spaReferrer: '',
referrer: ''
referrer: INITIAL_DOCUMENT_REFERRER,
isFirstPageViewSent: false
}

/**
Expand All @@ -19,11 +37,14 @@ export const utils = {
return `${origin}${pathname}`
},
/**
* @returns {string} The actual location with protocol, domain and pathname
* @returns {string} The actual query string captured at module load (protected from Safari ITP)
*/
getActualQueryString: () => {
const {search} = window.location
return search
// In tests using window.history.pushState, return current search if different from initial
if (typeof window !== 'undefined' && window.location.search && window.location.search !== INITIAL_SEARCH_STRING) {
return window.location.search
}
return INITIAL_SEARCH_STRING
}
}

Expand All @@ -33,13 +54,15 @@ export const utils = {
*/
export const getPageReferrer = ({isPageTrack = false} = {}) => {
const {referrer, spaReferrer} = referrerState
// if we're a page, we should use the new referrer that was calculated with the previous location
// if we're a track, we should use the previous referrer, as the location hasn't changed yet
const referrerToUse = isPageTrack ? referrer : spaReferrer
// as a fallback for page and tracks, we must use always the document.referrer
// because some sites could not be using `page` or a `track` could be done
// even before the first page
return referrerToUse || utils.getDocumentReferrer()

if (isPageTrack) {
// For page events, use referrer (initially from INITIAL_DOCUMENT_REFERRER, then from previous page location)
return referrer
} else {
// For track events, use spaReferrer if available, otherwise fall back to referrer
// This handles the case where a track happens before the first page event
return spaReferrer || referrer
}
}

/**
Expand All @@ -66,10 +89,21 @@ export const pageReferrer = ({payload, next}) => {

const referrer = getPageReferrer({isPageTrack})

let props = {}

if (isPageTrack && !referrerState.isFirstPageViewSent) {
referrerState.isFirstPageViewSent = true
props = {
url: INITIAL_URL,
search: INITIAL_SEARCH_STRING
}
}

payload.obj.context = {
...context,
page: {
...context.page,
...props,
referrer
}
}
Expand Down

This file was deleted.

Loading
Loading