Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support targeted replay capture #10

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
32 changes: 12 additions & 20 deletions .github/workflows/feature-branch-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,33 @@ jobs:
run: |
yarn test

- name: Lint all packages
run: |
yarn lint

- name: Configure Git User
run: |
git config --global user.name amplitude-sdk-bot
git config --global user.email amplitude-sdk-bot@users.noreply.github.com

- name: Configure NPM User
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm whoami

# Converted to all lowercase and stripped of non-letter characters
- name: Transform feature branch name
run: |
echo "PREID=$(echo '${{ steps.branch-name.outputs.current_branch }}' | tr -cd '[:lower:]')" >> $GITHUB_ENV

# Use --no-push to prevent pushing to remote
# Example:
# - feature-branch-name -> featurebranchname
# - minor: 1.0.0 -> 1.1.0-featurebranchname.0
- name: Dry run pre-release version
if: ${{ github.event.inputs.releaseType == 'dry-run' }}
run: |
GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:version -- -y --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.branch-name.outputs.current_branch }} --no-changelog --no-push

- name: Pre-release version
if: ${{ github.event.inputs.releaseType == 'prerelease' }}
run: |
GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:version -- -y --no-private --conventional-prerelease --preid ${{ env.PREID }} --allow-branch ${{ steps.branch-name.outputs.current_branch }} --create-release github
- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version-file: './package.json,./package-lock.json'
pre-release: 'true'
pre-release-identifier: ${{ env.PREID }}

# Use 'from git' option if `lerna version` has already been run
- name: Publish Release to NPM
if: ${{ github.event.inputs.releaseType == 'prerelease' }}
run: |
GH_TOKEN=${{ secrets.GH_PUBLISH_TOKEN }} npm run deploy:publish -- from-git -y --ignore-scripts --pre-dist-tag ${{ env.PREID }}
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.4.1-targetedcapture.0](https://github.com/amplitude/segment-session-replay-wrapper/compare/v0.4.0...v0.4.1-targetedcapture.0) (2024-08-23)


### Features

* support targeted replay capture ([3d7a2c0](https://github.com/amplitude/segment-session-replay-wrapper/commit/3d7a2c053794a150a44ad0afde4af110d4bcdc27))



# [0.4.0](https://github.com/amplitude/segment-session-replay-wrapper/compare/v0.3.1...v0.4.0) (2024-08-23)


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplitude/segment-session-replay-wrapper",
"version": "0.4.0",
"version": "0.4.1-targetedcapture.0",
"description": "Wrapper to enable usage of Segment with Amplitude's Session Replay product",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand All @@ -9,7 +9,7 @@
"author": "Amplitude Inc",
"license": "MIT",
"dependencies": {
"@amplitude/session-replay-browser": "1.13.6",
"@amplitude/session-replay-browser": "1.14.0-srtargeting.0",
"@segment/analytics-next": ">=1 <2",
"js-cookie": "^3.0.5",
"tslib": "^2.4.1"
Expand Down Expand Up @@ -61,4 +61,4 @@
"typescript": "5.4.5"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
11 changes: 11 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const updateSessionIdAndAddProperties = async (ctx: Context) => {
await sessionReplay.setSessionId(nextSessionId, deviceId).promise;
}

await sessionReplay.evaluateTargetingAndCapture({
event: {
event_type: ctx.event.event || '',
event_properties: ctx.event.properties,
time: ctx.event.timestamp instanceof Date ? ctx.event.timestamp.getTime() : undefined,
},
userProperties: ctx.event.traits,
});
const sessionReplayProperties = sessionReplay.getSessionReplayProperties();
const properties = {
...ctx.event.properties,
Expand Down Expand Up @@ -59,6 +67,7 @@ export const createSegmentActionsPlugin = async ({
sessionId: storedSessionId,
deviceId: deviceId || undefined,
version: { type: 'segment', version: VERSION },
userProperties: user.traits(),
}).promise;
},

Expand All @@ -78,6 +87,8 @@ export const createSegmentActionsPlugin = async ({
const sessionId = sessionReplay.getSessionId();
sessionId && (await sessionReplay.setSessionId(sessionId, deviceId).promise);

await sessionReplay.evaluateTargetingAndCapture({ userProperties: ctx.event.traits });

return ctx;
},
};
Expand Down
88 changes: 57 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,85 @@
"@amplitude/analytics-types" "^2.6.0"
tslib "^2.4.1"

"@amplitude/analytics-remote-config@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@amplitude/analytics-remote-config/-/analytics-remote-config-0.4.0.tgz#e9835836ef40c6b2e72bc8c7a88803dda5559556"
integrity sha512-ilp9Dz8Z92V9Wilmz8XIbvEbtuVaN65+jM06JP8I7wL8eNOHVIi4HcI151BzIyekjbprbS1w18Ps3dj2sHlFXA==
"@amplitude/analytics-remote-config@^0.3.4":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@amplitude/analytics-remote-config/-/analytics-remote-config-0.3.4.tgz#a9a3fd8db9585dd45e4ebd75da8cd31408606dc1"
integrity sha512-IdGJTJiHzkpUJtIOK3zmPtmMQ6p2z1U7Yxc4oC3kFK5+7MMZKDY1eFjszRzk/wQhCumPEp9MyGVd/SiN3LoBUQ==
dependencies:
"@amplitude/analytics-client-common" ">=1 <3"
"@amplitude/analytics-core" ">=1 <3"
"@amplitude/analytics-types" ">=1 <3"
idb "^8.0.0"
tslib "^2.4.1"

"@amplitude/analytics-types@>=1 <3", "@amplitude/analytics-types@^2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@amplitude/analytics-types/-/analytics-types-2.6.0.tgz#00d1957d3f5eecb85e00ef4a1b2f65c497967d46"
integrity sha512-7MSENvLCTGjec7K45JT+RcOuoPTCvq1MMq/HRLiQK/BMR4taX7f/uXldEc8b//o+ZZP45IBqFroR7Bl8LwJQrQ==

"@amplitude/rrdom@^2.0.0-alpha.20":
version "2.0.0-alpha.20"
resolved "https://registry.yarnpkg.com/@amplitude/rrdom/-/rrdom-2.0.0-alpha.20.tgz#55b87f30b0a933581146230c76e105c07cb3a3d4"
integrity sha512-OZOqHvpYARmc8vJQG1OfAT+3R0/eZJ7SU7UGTmuZR5nM+NRvNqEBahdxOwueQOG+Dofi9gX4YiX4ekwMXJ+R/A==
"@amplitude/experiment-core@0.7.2":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@amplitude/experiment-core/-/experiment-core-0.7.2.tgz#f94219d68d86322e8d580c8fbe0672dcd29f86bb"
integrity sha512-Wc2NWvgQ+bLJLeF0A9wBSPIaw0XuqqgkPKsoNFQrmS7r5Djd56um75In05tqmVntPJZRvGKU46pAp8o5tdf4mA==
dependencies:
js-base64 "^3.7.5"

"@amplitude/rrdom@^2.0.0-alpha.19":
version "2.0.0-alpha.19"
resolved "https://registry.yarnpkg.com/@amplitude/rrdom/-/rrdom-2.0.0-alpha.19.tgz#b2f3de23862d7ba6989351e4a08144f90413fa38"
integrity sha512-zqPnAjwlUEPGHq2JpTnPjpI9LRdJeN0koaJ7dbQeQI5eJcNFtOjsLWpYgkBHjyQKKOh5FhBG0KVdX4L7y1Rmfg==
dependencies:
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.20"
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.19"

"@amplitude/rrweb-snapshot@^2.0.0-alpha.20":
version "2.0.0-alpha.20"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb-snapshot/-/rrweb-snapshot-2.0.0-alpha.20.tgz#28cd20a0c4e43aa9c59b3fae4f1073814e982322"
integrity sha512-cSrAMyFTFnhkyt7m9SVciDRUgpg7OjJAxejDEyAYCDQo8b8cj6WXWS21kPSprILKL27Y/cvaDHTYuU74uTuIiA==
"@amplitude/rrweb-snapshot@^2.0.0-alpha.19":
version "2.0.0-alpha.19"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb-snapshot/-/rrweb-snapshot-2.0.0-alpha.19.tgz#a5c03ec52968a768827c20a8cc001dca6daae074"
integrity sha512-v+X3Ymdn0O4TBf4UFLJzNOWYxJqSu3fF+/FuXjORf74xc+5L6Tme/eY6mNZHigHJOGyIyFhlQXUUKm+CBiJcDw==

"@amplitude/rrweb-types@^2.0.0-alpha.20":
version "2.0.0-alpha.20"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb-types/-/rrweb-types-2.0.0-alpha.20.tgz#a87f98e2ba8ba729c7453143207790ecb67348f6"
integrity sha512-TYR14QUDJ6OvDmWkik5atfBmmGRmPZCz1fyNK+hy7gVtfJ24R4oDmpL2ntwTlflYwSzcTACeGvDw0CQnekDkPw==
"@amplitude/rrweb-types@^2.0.0-alpha.19":
version "2.0.0-alpha.19"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb-types/-/rrweb-types-2.0.0-alpha.19.tgz#96a4d12341e4130f652959e708e2ced37c672220"
integrity sha512-Po0/Gp24Guvye/jr3aYPAVSqijQr1CETWSCK4DEriE8h03PcMs41JDeEjlJpHL/yHj76S6L7t3VCbiPOWT/OIg==
dependencies:
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.20"
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.19"

"@amplitude/rrweb@2.0.0-alpha.20":
version "2.0.0-alpha.20"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb/-/rrweb-2.0.0-alpha.20.tgz#201069ff3f511c020c093e7dd92172f09ff8a105"
integrity sha512-r2a/ZUTSXwptAsc22pFBvbcb5ixt2Y2l5/HFeyDV7K/bT2uxXoytERZlPIuHuhaK112pnWdAGPRWIqf+IFQGkQ==
"@amplitude/rrweb@2.0.0-alpha.19":
version "2.0.0-alpha.19"
resolved "https://registry.yarnpkg.com/@amplitude/rrweb/-/rrweb-2.0.0-alpha.19.tgz#b1292862f65bc777128715497c9719476e47908b"
integrity sha512-bemevshhw7gVYFT5fMCfRQZgQPV0rsY0zAb91NmRVrOivGXOQtSyPZ5othnGn2it4x5kFZyGAIAlMPtWCqhM8A==
dependencies:
"@amplitude/rrdom" "^2.0.0-alpha.20"
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.20"
"@amplitude/rrweb-types" "^2.0.0-alpha.20"
"@amplitude/rrdom" "^2.0.0-alpha.19"
"@amplitude/rrweb-snapshot" "^2.0.0-alpha.19"
"@amplitude/rrweb-types" "^2.0.0-alpha.19"
"@types/css-font-loading-module" "0.0.7"
"@xstate/fsm" "^1.4.0"
base64-arraybuffer "^1.0.1"
fflate "^0.4.4"
mitt "^3.0.0"

"@amplitude/session-replay-browser@1.13.6":
version "1.13.6"
resolved "https://registry.yarnpkg.com/@amplitude/session-replay-browser/-/session-replay-browser-1.13.6.tgz#58b7210af65d580902dd1018e062831c02e7fe94"
integrity sha512-zrdbVpq7tadZQIRBFFz2jCmSxtjItyd42Zp2dUH+Q9cI412lxcUC2DxOC0jrtuz1VK7gW0vjdI+4Ada1tgO97g==
"@amplitude/session-replay-browser@1.14.0-srtargeting.0":
version "1.14.0-srtargeting.0"
resolved "https://registry.yarnpkg.com/@amplitude/session-replay-browser/-/session-replay-browser-1.14.0-srtargeting.0.tgz#88e0dba66c7ffd7d84d8adc2ed0b174028ffe751"
integrity sha512-624kU28EN9uQG+P2ysZPRmaiLqrSFzWoI7tNzvmNCMBZ/FUxT1L2DarvwVZMsKtYt0eGQNgzbSRizherrU3V0A==
dependencies:
"@amplitude/analytics-client-common" ">=1 <3"
"@amplitude/analytics-core" ">=1 <3"
"@amplitude/analytics-remote-config" "^0.4.0"
"@amplitude/analytics-remote-config" "^0.3.4"
"@amplitude/analytics-types" ">=1 <3"
"@amplitude/rrweb" "2.0.0-alpha.20"
"@amplitude/rrweb" "2.0.0-alpha.19"
"@amplitude/targeting" "0.2.0"
idb "^8.0.0"
tslib "^2.4.1"

"@amplitude/targeting@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@amplitude/targeting/-/targeting-0.2.0.tgz#b0c8342fae929c85333190a71a5bc0b7f369010f"
integrity sha512-/50ywTrC4hfcfJVBbh5DFbqMPPfaIOivZeb5Gb+OGM03QrA+lsUqdvtnKLNuWtceD4H6QQ2KFzPJ5aAJLyzVDA==
dependencies:
"@amplitude/analytics-client-common" ">=1 <3"
"@amplitude/analytics-core" ">=1 <3"
"@amplitude/analytics-types" ">=1 <3"
"@amplitude/experiment-core" "0.7.2"
idb "^8.0.0"
tslib "^2.4.1"

Expand Down Expand Up @@ -2644,6 +2665,11 @@ jest@29.7.0:
import-local "^3.0.2"
jest-cli "^29.7.0"

js-base64@^3.7.5:
version "3.7.7"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.7.tgz#e51b84bf78fbf5702b9541e2cb7bfcb893b43e79"
integrity sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==

js-cookie@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.1.tgz#9e39b4c6c2f56563708d7d31f6f5f21873a92414"
Expand Down