diff --git a/packages/sui-segment-wrapper/package.json b/packages/sui-segment-wrapper/package.json index a285355a4..94a78547c 100644 --- a/packages/sui-segment-wrapper/package.json +++ b/packages/sui-segment-wrapper/package.json @@ -5,12 +5,14 @@ "main": "lib/index.js", "scripts": { "lib": "sui-js-compiler", + "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:client:watch": "npm run test:client -- --watch", "test:client": "sui-test browser --src-pattern=src/index.js -H", "test": "npm run test:client", "test:umd": "npm run umd && npx servor ./umd", - "umd": "sui-bundler lib src-umd/index.js -o umd/ -p --root" + "umd": "VERSION=$npm_package_version sui-bundler lib src-umd/index.js -o umd/ -p --root" }, "author": "", "license": "ISC", @@ -22,5 +24,12 @@ "@s-ui/bundler": "9", "@s-ui/js-compiler": "1", "@s-ui/test": "8" + }, + "config": { + "sui-bundler": { + "env": [ + "VERSION" + ] + } } } diff --git a/packages/sui-segment-wrapper/src/segmentWrapper.js b/packages/sui-segment-wrapper/src/segmentWrapper.js index ed2c98b8c..f990e39fe 100644 --- a/packages/sui-segment-wrapper/src/segmentWrapper.js +++ b/packages/sui-segment-wrapper/src/segmentWrapper.js @@ -146,7 +146,8 @@ export const decorateContextWithNeededData = async ({event = '', context = {}}) integrations: { ...context.integrations, ...integrations - } + }, + clientVersion: `segment-wrapper@${process.env.VERSION ?? '0.0.0'}` } } diff --git a/packages/sui-segment-wrapper/test/segmentWrapperSpec.js b/packages/sui-segment-wrapper/test/segmentWrapperSpec.js index e3dd00276..3bf1cb7c4 100644 --- a/packages/sui-segment-wrapper/test/segmentWrapperSpec.js +++ b/packages/sui-segment-wrapper/test/segmentWrapperSpec.js @@ -755,7 +755,8 @@ describe('Segment Wrapper', function () { gdpr_privacy_advertising: 'declined', context: { integrations - } + }, + clientVersion: 'segment-wrapper@0.0.0' } const {traits} = spy.getCall(0).firstArg.obj.context