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: Expose block selector config from rrweb to SR plugin/SDK. #631

Open
wants to merge 250 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
250 commits
Select commit Hold shift + click to select a range
5cac08d
build: allow lerna version commands from v1.x branch
kevinpagtakhan Jun 5, 2023
cd8e6bd
build: support release jobs for multiple versions (#403)
kevinpagtakhan Jun 5, 2023
05eb25a
chore(release): publish
amplitude-sdk-bot Jun 6, 2023
54030b6
Merge branch 'v1.x' into main-fix-v1
kevinpagtakhan Jun 6, 2023
367cfdd
build: add dist tag for published versions (#405)
kevinpagtakhan Jun 6, 2023
08dca3e
chore(release): publish
amplitude-sdk-bot Jun 6, 2023
d309141
build: remove unnecessary beta script guard (#409)
kevinpagtakhan Jun 6, 2023
ce17aab
fix: don't automatically start new session on setUserId (#400)
justin-fiedler Jun 6, 2023
8f527e4
chore(release): publish
amplitude-sdk-bot Jun 6, 2023
a48ddc5
docs: update instructions and docs to reference 1.0 (#419)
kevinpagtakhan Jun 8, 2023
86de7bd
feat: log response body from API to logger (#415)
justin-fiedler Jun 8, 2023
0c03a57
chore(release): publish
amplitude-sdk-bot Jun 8, 2023
c6c82ba
feat: added extendSession() method to Browser Client (#425)
justin-fiedler Jun 12, 2023
5cfe645
chore(release): publish
amplitude-sdk-bot Jun 13, 2023
52f7b08
fix: do not fetch advertising Id if adid tracking is disabled (#424)
falconandy Jun 13, 2023
4773997
chore(release): publish
amplitude-sdk-bot Jun 13, 2023
b46f2f4
fix: session end events being assigned to a different session id (#42…
kevinpagtakhan Jun 14, 2023
0183372
chore(release): publish
amplitude-sdk-bot Jun 14, 2023
9f0a180
build: update dist-tag (#418)
kevinpagtakhan Jun 14, 2023
bab630d
fix: compact logged response body's for AMP-77261 (#430)
justin-fiedler Jun 14, 2023
301ba1e
chore(release): publish
amplitude-sdk-bot Jun 14, 2023
569464c
feat: add option for instance name (#428) (#442)
kevinpagtakhan Jun 16, 2023
b31226d
fix: types for plugins to be env specific (#440) (#441)
kevinpagtakhan Jun 16, 2023
ed299ba
feat(plugins): mvp of session replay plugin
May 30, 2023
c88d85a
feat(plugins): implemented retry logic for session replay
May 31, 2023
e85de00
feat(plugins): batching requests at max list size
May 31, 2023
0788956
feat(plugins): implementing indexeddb storage for session replay
Jun 1, 2023
9530501
feat(plugins): add indentifier to session start
Jun 5, 2023
86ae48b
feat(plugins): fix for first event fired for session replay
Jun 6, 2023
c30e3db
feat(plugins): restart the recording on session start
Jun 8, 2023
216f4d3
feat(plugins): session replay setting up tests
Jun 21, 2023
6211a3e
feat(plugins): add test coverage to session replay plugin
Jun 22, 2023
f9d98cd
feat(plugins): cleanup and update readme and changelog
Jun 22, 2023
e371754
feat(plugins): complete test coverage
Jun 22, 2023
1365bae
feat(plugins): add packFn to session replay
Jun 23, 2023
1b8f037
feat(plugins): pr feedback
Jun 26, 2023
84b349c
feat(plugins): update yarn.lock after changing branch base
Jun 26, 2023
83ce837
fix: add app_set_id, idfa and idfv support (#456)
falconandy Jun 26, 2023
72f4348
feat(plugins): adjust timing of setup to capture early sent events
Jun 26, 2023
01c20d6
chore(release): publish
amplitude-sdk-bot Jun 26, 2023
07fc403
feat(plugins): update name of property for session replay
Jun 27, 2023
2c76247
feat(plugins): change file names
Jun 27, 2023
61185ac
feat(plugins): expose function as external interface
Jun 27, 2023
4ace87d
feat(plugins): remove mistake addition
Jun 27, 2023
ba968f8
feat(plugins): session replay plugin (#393)
kwalker3690 Jun 28, 2023
b782eb3
chore(release): publish
amplitude-sdk-bot Jun 28, 2023
902aa39
fix: missing core dependency for web attribution (#462)
kevinpagtakhan Jun 30, 2023
1394ddb
fix: allow plugins to teardown to remove listeners (#463)
kevinpagtakhan Jun 30, 2023
603e3ef
fix: allow literal values for plugin type (#468)
kevinpagtakhan Jul 5, 2023
712158b
fix: handle concurrent cookie testing (#465)
kevinpagtakhan Jul 3, 2023
4ebf96b
fix: handle concurrent history push state calls (#466)
kevinpagtakhan Jul 3, 2023
bc426d8
chore(release): publish
amplitude-sdk-bot Jul 5, 2023
fadd7c0
fix(plugins): update timing of sending batches of session replay events
Jul 6, 2023
fc263ed
fix(plugins): remove console log
Jul 6, 2023
721a399
fix(plugins): need to send first two events immediately for replayer …
Jul 6, 2023
59802fb
fix(plugins): pr feedback
Jul 10, 2023
fbd7ee2
fix(plugins): update timing of sending batches of session replay even…
kwalker3690 Jul 10, 2023
ee064fe
chore(release): publish
amplitude-sdk-bot Jul 11, 2023
1a55aee
fix(plugins): change timing of record upon initialization for session…
Jul 13, 2023
708d4b9
fix(plugins): should only initiate recording on session start if reco…
Jul 13, 2023
a26f585
fix(plugins): change timing of record upon initialization for session…
kwalker3690 Jul 13, 2023
392e3d9
chore(release): publish
amplitude-sdk-bot Jul 13, 2023
d2e9a0c
feat(plugins): solve timing issues with multiple tabs
Jul 19, 2023
b73a4d8
test(plugins): update tests for session replay
Jul 20, 2023
b770d44
fix(plugins): reduce min interval to 500ms
Jul 20, 2023
69f9b34
fix(plugins): Solve timing and duplicated batch issues with session r…
kwalker3690 Jul 20, 2023
2c95641
chore(release): publish
amplitude-sdk-bot Jul 20, 2023
d85e230
feat: user agent plugin (#503)
yuhao900914 Jul 25, 2023
7fb6059
fix(plugins): stop recording when document.hasFocus is false
Jul 26, 2023
8f5e90a
fix(plugins): stop recording when document.hasFocus is false (#506)
kwalker3690 Jul 26, 2023
cf93eaf
fix: react-native fix context plugin to include app version on mobile…
bgiori Jul 26, 2023
6d9cf5f
chore(release): publish
amplitude-sdk-bot Jul 26, 2023
6aeb511
feat(plugins): add default tracking of sessions to session replay plugin
Jul 10, 2023
bcabfa4
feat(plugins): add a configuration option for sampling rate
Jul 10, 2023
25bd516
feat(plugins): abide by global opt out for session recording
Jul 10, 2023
5c04c3c
feat(plugins): update config additions to store in idb
Jul 26, 2023
5438a43
fix(plugins): ensure config.optout takes priority over sample rate
Jul 26, 2023
ed20cf2
fix(plugins): update README for session replay
Jul 26, 2023
b8ebbbc
feat(plugins): Adding configuration options to session replay plugin …
kwalker3690 Jul 26, 2023
e46a42e
feat(plugins): add masking controls to session replay and reorganize …
Jul 27, 2023
1b45195
feat(plugins): add masking controls to session replay and reorganize …
kwalker3690 Jul 27, 2023
7587aac
chore(release): publish
amplitude-sdk-bot Jul 27, 2023
ed03435
fix: updated session logic and tests (#447)
falconandy Jul 27, 2023
fb261b8
feat(plugins): add option to block elements based on amp-block class …
Jul 27, 2023
b08eca4
feat(plugins): add option to block elements based on amp-block class …
Jul 27, 2023
66d8395
chore(release): publish
amplitude-sdk-bot Jul 27, 2023
675cb82
fix(plugins): prevent any activity from occurring if document does no…
Jul 27, 2023
ec57c2c
fix(plugins): prevent any activity from occurring in session replay p…
Jul 27, 2023
856f91d
chore(release): publish
amplitude-sdk-bot Jul 27, 2023
2d4362f
chore: [email protected] (#513)
kevinpagtakhan Jul 31, 2023
d7c22fc
chore(release): publish
amplitude-sdk-bot Jul 31, 2023
1e8317b
fix(plugins): correctly fetch shouldRecord from store and clean up ol…
Jul 31, 2023
b279f0d
chore(release): publish
amplitude-sdk-bot Jul 31, 2023
0168653
feat(session replay eu): route rraffic to eu based on config
jackson-amplitude Jul 31, 2023
1e2a754
fix(plugins): correctly fetch shouldRecord from store and clean up ol…
Aug 1, 2023
e641477
chore(release): publish
amplitude-sdk-bot Aug 1, 2023
c9cb8b3
feat(session replay eu): route traffic to eu based on config (#515)
jackson-amplitude Aug 1, 2023
2857038
fix(plugins): fix edge case when opening tab in background
Aug 1, 2023
2be9327
fix(plugins): fix edge case when opening tab in background (#517)
Aug 2, 2023
a9293cb
chore(release): publish
amplitude-sdk-bot Aug 2, 2023
4c7e579
fix(plugins): use hash to calculate is session is included in sample
Aug 3, 2023
82a0da4
fix(plugins): use hash to calculate is session is included in sample …
Aug 4, 2023
ca2bca1
chore(release): publish
amplitude-sdk-bot Aug 4, 2023
5899917
test(plugins): add test for sending events that are not current sessi…
Aug 4, 2023
e4d2ba0
test(plugins): add test for sending events that are not current sessi…
Aug 7, 2023
8d4afd6
feat(plugins): add teardown functionality to session replay plugin
Aug 7, 2023
d3538a0
feat(plugins): add teardown functionality to session replay plugin (#…
Aug 7, 2023
5b8d427
chore(release): publish
amplitude-sdk-bot Aug 7, 2023
31d5c35
feat: page view v1 enrichment plugin (#524)
yuhao900914 Aug 8, 2023
f9bb216
chore(release): publish
amplitude-sdk-bot Aug 8, 2023
bb746e8
chore: add publish script to plugins to upload the script into cdn (#…
yuhao900914 Aug 9, 2023
a952850
chore: [email protected] (#526)
yuhao900914 Aug 9, 2023
2f2b22a
chore(release): publish
amplitude-sdk-bot Aug 9, 2023
586cbc5
fix: migrate legacy data (#486)
falconandy Aug 10, 2023
2957c0b
chore(release): publish
amplitude-sdk-bot Aug 10, 2023
ed50fb2
chore: fix TODO warning (#532)
falconandy Aug 11, 2023
417d07f
chore(release): publish
amplitude-sdk-bot Aug 11, 2023
4491652
fix(plugin): override lerna autocorrect packages
Aug 11, 2023
499617d
fix(plugin): override lerna autocorrect packages (#534)
Aug 11, 2023
4e8c567
fix(plugins): add analytics-core as dependency
Aug 11, 2023
ee85df8
chore(release): publish
amplitude-sdk-bot Aug 11, 2023
9ef5729
fix(plugins): add analytics-core as dependency (#535)
Aug 11, 2023
a04860f
chore(release): publish
amplitude-sdk-bot Aug 11, 2023
deeb074
feat: add ga events forwarder plugin (#530)
kevinpagtakhan Aug 14, 2023
11b652e
fix: set ga events forwarder plugin private (#537)
kevinpagtakhan Aug 14, 2023
e94b97b
fix: add allowed hostname for ga events forwarder (#538)
kevinpagtakhan Aug 15, 2023
3fdfc53
fix: add example react-native plugin to get location, remove unused l…
falconandy Aug 15, 2023
cbe87af
fix: replace tracking Id with measurement Id (#539)
kevinpagtakhan Aug 15, 2023
83cf780
chore(release): publish
amplitude-sdk-bot Aug 15, 2023
c06209a
feat: update Android files to support recent React Native versions (#…
falconandy Aug 15, 2023
cde2f7f
chore(release): publish
amplitude-sdk-bot Aug 15, 2023
651144f
fix(plugins): add error handling to session replay and bump rrweb ver…
Aug 16, 2023
3fd9ff5
fix: limit storage size
Mercy811 Aug 16, 2023
810e32b
Revert "fix: limit storage size"
Mercy811 Aug 16, 2023
62bdf38
fix(plugins): add test coverage
Aug 17, 2023
7faeff3
fix(plugins): add error handling to session replay and bump rrweb ver…
Aug 17, 2023
b6c95e7
chore(release): publish
amplitude-sdk-bot Aug 17, 2023
057e4d9
fix: collect 'carrier' data in react-native iOS (#545)
falconandy Aug 17, 2023
348b1ec
chore(release): publish
amplitude-sdk-bot Aug 17, 2023
8a1f1f5
docs: announcement for ma in maintenance mode (#544)
yuhao900914 Aug 17, 2023
2e1e8dd
fix: collect 'country' data in react-native (#547)
falconandy Aug 18, 2023
64637ba
fix: add return type of proxied function (#546)
kevinpagtakhan Aug 18, 2023
52d2e18
fix: limit local storage size (#543)
Mercy811 Aug 21, 2023
bfcdb59
fix: remove circular dependencies to unblock release (#553)
falconandy Aug 22, 2023
72c37d1
chore(release): publish
amplitude-sdk-bot Aug 22, 2023
525b4ad
feat(browser): set optOut config in analytics connector
Aug 22, 2023
c2660b4
chore(all): deduplicate yarn.lock
Aug 22, 2023
ce20bdd
test(analytics-connector): add test for setOptOut
Aug 22, 2023
bf38f53
feat(browser): set optOut config in analytics connector (#556)
Aug 22, 2023
2875252
chore(release): publish
amplitude-sdk-bot Aug 22, 2023
64500e7
feat: dedupe det events & ga automatic events (#558)
kevinpagtakhan Aug 22, 2023
8c53ef1
feat(session replay): introduce standalone version of session replay …
Aug 18, 2023
ceef7c8
chore(session replay): clean up commented lines
Aug 22, 2023
78ad90a
fix(session replay): update documentation
Aug 23, 2023
23e8afc
fix(session replay) remove changes to plugin
Aug 23, 2023
777e3d8
fix(session replay): update log message
Aug 23, 2023
d177337
test(session replay): add more test coverage
Aug 23, 2023
5b332e4
fix(session replay): use AmplitudeReturn type for async init
Aug 24, 2023
4fb16f8
fix(session replay): pr feedback
Aug 24, 2023
6533980
feat: modify "event.library" value for events forwarded from google a…
kevinpagtakhan Aug 24, 2023
93550e2
test: enrich ga transformed events with ga session id (#562)
kevinpagtakhan Aug 24, 2023
b573ef5
fix: support regional ga endpoints (#563)
kevinpagtakhan Aug 24, 2023
c987ffd
fix: set user id and device id from ga events (#565)
kevinpagtakhan Aug 24, 2023
a8b7236
chore: prepare ga forwarder release (#566)
kevinpagtakhan Aug 25, 2023
3097e60
chore(release): publish
amplitude-sdk-bot Aug 25, 2023
813aaf9
feat(session replay): introduce standalone version of session replay …
Aug 25, 2023
bfd0e08
chore(release): publish
amplitude-sdk-bot Aug 25, 2023
757032f
feat: add auto-tracking plugin (#570)
liuyang1520 Aug 31, 2023
101a186
chore(release): publish
amplitude-sdk-bot Aug 31, 2023
34647ea
refactor(plugin-auto-tracking-browser): remove ingestion metadata opt…
liuyang1520 Sep 5, 2023
0d18ae4
chore(release): publish
amplitude-sdk-bot Sep 5, 2023
fd20ab7
docs(session replay): update readme to reflect collection
Sep 6, 2023
8a8921e
refactor(session replay plugin): use session replay sdk to power plugin
Aug 25, 2023
2c63830
fix(session replay plugin): update dependencies and remove eslint ove…
Aug 31, 2023
41faedc
fix(session replay plugin): delete unused file
Aug 31, 2023
f26ab9c
fix(session replay plugin): remove use of client-common
Sep 5, 2023
ada95d7
fix(session replay plugin): test
Sep 6, 2023
8ea9c27
docs(session replay): update readme to reflect collection (#574)
Sep 6, 2023
9f3015e
refactor(session replay plugin): use session replay sdk to power plug…
Sep 6, 2023
13dbb29
fix: config values should take precedence over nativemodule in Contex…
falconandy Sep 8, 2023
f361d34
chore(release): publish
amplitude-sdk-bot Sep 8, 2023
ab6c064
feat(session replay): add getSessionReplayProperties method
Sep 11, 2023
b3dc18d
feat(session replay): add getSessionReplayProperties method (#578)
Sep 11, 2023
13f2829
chore(release): publish
amplitude-sdk-bot Sep 11, 2023
597201a
fix(session replay): expose getSessionReplayProperties externally
Sep 12, 2023
de3bb5f
fix(session replay): expose getSessionReplayProperties externally (#580)
Sep 12, 2023
0e2a9ed
chore(release): publish
amplitude-sdk-bot Sep 12, 2023
fa72e9b
fix(session replay): remove beta tag from package.json to update publ…
Sep 12, 2023
5cf1f2d
fix(session replay): remove beta tag from package.json to update publ…
Sep 12, 2023
1486b28
chore(release): publish
amplitude-sdk-bot Sep 12, 2023
60df827
fix(session replay): Update endpoint for session replay and only retr…
Sep 18, 2023
d705539
fix(session replay): Update endpoint for session replay and only retr…
Sep 18, 2023
f30d116
chore(release): publish
amplitude-sdk-bot Sep 18, 2023
7b3b571
fix(session replay): opt out should take effect immediately
Sep 20, 2023
0645fb2
fix(session replay) set max retries to cap at 1 and update to new api…
Sep 21, 2023
756fb40
fix(session replay) set max retries to cap at 1 and update to new api…
Sep 21, 2023
be0375a
chore(release): publish
amplitude-sdk-bot Sep 21, 2023
7330d49
fix(session replay plugin): update plugin to use the sessionReplayPro…
Sep 21, 2023
d1cd748
fix(session replay plugin): update plugin to use the sessionReplayPro…
Sep 21, 2023
18034a8
chore(release): publish
amplitude-sdk-bot Sep 21, 2023
938b5d5
fix(session replay): test identity store false case and opt out in mi…
Sep 21, 2023
5af910a
build: temp disable auto-tracking package publish (#590)
liuyang1520 Sep 22, 2023
5374314
fix(session replay): opt out should take effect immediately (#586)
jxiwang Sep 26, 2023
c5907ef
fix: Amp 85112 set user id is not queued in snippet v1 (#592)
justin-fiedler Sep 27, 2023
0fd37e7
chore(release): publish
amplitude-sdk-bot Sep 27, 2023
d4a1b33
feat(session replay): add metadata to headers
Oct 6, 2023
1bfa2a2
feat: update auto tracking plugin (#589)
liuyang1520 Oct 6, 2023
bc2afba
chore(release): publish
amplitude-sdk-bot Oct 6, 2023
6d15bfb
feat(session replay): add metadata to headers
Oct 11, 2023
222920a
feat(session replay): add metadata to headers
Oct 11, 2023
feb18ca
refactor: rename to default-event-tracking-advanced plugin (#599)
liuyang1520 Oct 11, 2023
1a81f7c
chore(release): publish
amplitude-sdk-bot Oct 11, 2023
e4debe2
feat(session replay): change non-actionable errors to warnings
Oct 11, 2023
ea6e54e
feat(session replay): add metadata to headers (#598)
jxiwang Oct 13, 2023
33c682d
Update README.md
jxiwang Oct 13, 2023
1a2d6a4
chore(release): publish
amplitude-sdk-bot Oct 17, 2023
8f96d1c
fix(session replay): use internal fork of rrweb
Oct 24, 2023
5b143f4
fix(session replay): use internal fork of rrweb (#604)
Oct 26, 2023
95f7249
fix: log error trace in catch blocks (#605)
kevinpagtakhan Oct 26, 2023
eb9f818
chore(release): publish
amplitude-sdk-bot Oct 26, 2023
404d09e
feat: make auto-tracking solely use css selector allowlist (#606)
liuyang1520 Oct 26, 2023
517fa48
chore(release): publish
amplitude-sdk-bot Oct 27, 2023
afe1cc2
fix: remove event stopPropagation (#608)
liuyang1520 Oct 27, 2023
e60ab0a
chore(release): publish
amplitude-sdk-bot Oct 27, 2023
92c412b
fix: add filter back to handle current node (#609)
liuyang1520 Oct 27, 2023
2b421dc
chore(release): publish
amplitude-sdk-bot Oct 27, 2023
b425d44
fix: handle text node throw error issue (#610)
liuyang1520 Oct 27, 2023
ab0a91a
chore(release): publish
amplitude-sdk-bot Oct 27, 2023
03a67c9
feat: add session replay ID generic identifier to init/turnover
Oct 31, 2023
990ddaf
feat(session replay): parse sessionReplayId for sessionId and deviceId
Oct 31, 2023
60f6b04
fix(session replay): testing changes for sessionReplayId
Nov 1, 2023
c0f0c2d
feat: add default data attr selector (#612)
liuyang1520 Nov 1, 2023
0298edd
chore(release): publish
amplitude-sdk-bot Nov 1, 2023
a7ea04a
feat(session replay): remove session replay id interface and expose s…
Nov 2, 2023
b602627
feat(session replay): error check for session replay id generation
Nov 2, 2023
50990a1
feat: add session replay ID generic identifier to init/turnover (#611)
jxiwang Nov 2, 2023
ace1377
chore(release): publish
amplitude-sdk-bot Nov 2, 2023
83d156a
feat(session replay): remove recording terms
Nov 2, 2023
cd378b3
fix: skip parent element event when it is not target (#613)
liuyang1520 Nov 3, 2023
c636eea
chore(release): publish
amplitude-sdk-bot Nov 3, 2023
01ef397
feat(session replay): remove recording terms (#618)
jxiwang Nov 10, 2023
151a509
chore(release): publish
amplitude-sdk-bot Nov 10, 2023
16f7655
chore(release): publish
amplitude-sdk-bot Nov 16, 2023
7afb5c7
feat: integrate with selector (#620)
liuyang1520 Nov 16, 2023
004e0da
chore(session replay): manually bump version to 0.8.0
Nov 16, 2023
cb4a038
chore(session replay): manually bump version to 0.8.0 (#625)
jxiwang Nov 16, 2023
3955739
chore(release): publish
amplitude-sdk-bot Nov 16, 2023
09b33b7
feat: expose rrweb blockselector
jackson-amplitude Dec 5, 2023
98d1bd4
chore: remove validation logic due to perf concern
jackson-amplitude Dec 5, 2023
d71769a
chore: fix tests and coverage
jackson-amplitude Dec 5, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Types } from '@amplitude/analytics-react-native';
import GetLocation, { Location } from 'react-native-get-location';

// https://github.com/douglasjunior/react-native-get-location#install - install steps, usage.
export default class LocationPlugin implements Types.BeforePlugin {
name = 'getLocation';
type = Types.PluginType.BEFORE as any;
config: Types.Config | undefined;
location: Location | undefined;

async setup(config: Types.Config): Promise<undefined> {
this.config = config;
GetLocation.getCurrentPosition({
enableHighAccuracy: true,
timeout: 30000,
rationale: {
title: 'Location permission',
message: 'The app needs the permission to request your location.',
buttonPositive: 'Ok',
},
})
.then((location) => {
this.location = location;
})
.catch((e) => {
config?.loggerProvider?.error(e);
});

return undefined;
}

async execute(context: Types.Event): Promise<Types.Event> {
if (this.location) {
context.location_lat = this.location.latitude;
context.location_lng = this.location.longitude;
}
return context;
}
}
27 changes: 27 additions & 0 deletions examples/plugins/react-native-idfa-plugin/idfaPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Types } from '@amplitude/analytics-react-native';
import ReactNativeIdfaAaid from '@sparkfabrik/react-native-idfa-aaid';

export default class IdfaPlugin implements Types.BeforePlugin {
name = 'idfa';
type = Types.PluginType.BEFORE as any;
config: Types.Config | undefined;
idfa: string | null = null;

async setup(config: Types.Config): Promise<undefined> {
this.config = config;
try {
const info = await ReactNativeIdfaAaid.getAdvertisingInfo();
this.idfa = info.id;
} catch (e) {
config?.loggerProvider?.error(e);
}
return undefined;
}

async execute(context: Types.Event): Promise<Types.Event> {
if (this.idfa) {
context.idfa = this.idfa;
}
return context;
}
}
2 changes: 2 additions & 0 deletions examples/react-native/legacyDataMigration/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
4 changes: 4 additions & 0 deletions examples/react-native/legacyDataMigration/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native',
};
66 changes: 66 additions & 0 deletions examples/react-native/legacyDataMigration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
ios/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
/ios/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage
7 changes: 7 additions & 0 deletions examples/react-native/legacyDataMigration/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
};
1 change: 1 addition & 0 deletions examples/react-native/legacyDataMigration/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
99 changes: 99 additions & 0 deletions examples/react-native/legacyDataMigration/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import React from 'react';
import {Alert, NativeModules} from 'react-native';
import {Button, SafeAreaView, StyleSheet} from 'react-native';
import {createInstance} from '@amplitude/analytics-react-native';
import {getCookieName} from '@amplitude/analytics-client-common';
import {UUID, MemoryStorage, STORAGE_PREFIX} from '@amplitude/analytics-core';
import {Event, UserSession} from '@amplitude/analytics-types';
import MigrationChecker from './MigrationChecker';

interface MigrationModule {
prepareLegacyDatabase(
instanceName: string | undefined,
version: string,
): Promise<void>;
}

const migrationModule = NativeModules.MigrationModule as MigrationModule;

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
gap: 10,
},
});

function App(): JSX.Element {
return (
<SafeAreaView style={styles.container}>
<Button
title="Migrate Legacy V4"
onPress={() => migrateLegacyData('v4')}
/>
<Button
title="Migrate Legacy V3"
onPress={() => migrateLegacyData('v3')}
/>
<Button
title="Migrate Legacy Missing"
onPress={() => migrateLegacyData('vMissing')}
/>
</SafeAreaView>
);
}

async function migrateLegacyData(version: 'v4' | 'v3' | 'vMissing') {
let instanceName = UUID();
let apiKey = UUID();
let cookieName = getCookieName(apiKey);
let eventsKey = `${STORAGE_PREFIX}_${apiKey.substring(0, 10)}`;
await migrationModule.prepareLegacyDatabase(instanceName, version);

const cookieStorage1 = new MemoryStorage<UserSession>();
const storageProvider1 = new MemoryStorage<Event[]>();
const amplitude1 = createInstance();
await amplitude1.init(apiKey, undefined, {
instanceName,
cookieStorage: cookieStorage1,
storageProvider: storageProvider1,
optOut: true,
trackingSessionEvents: false,
}).promise;

let checker1 = new MigrationChecker(version);
let userSession1 = await cookieStorage1.get(cookieName);
const events1 = await storageProvider1.get(eventsKey);
checker1.checkUserSession(userSession1);
checker1.checkEvents(events1);

const cookieStorage2 = new MemoryStorage<UserSession>();
const storageProvider2 = new MemoryStorage<Event[]>();
const amplitude2 = createInstance();
await amplitude2.init(apiKey, undefined, {
instanceName,
cookieStorage: cookieStorage2,
storageProvider: storageProvider2,
optOut: true,
trackingSessionEvents: false,
}).promise;

let checker2 = new MigrationChecker(version);
let userSession2 = await cookieStorage2.get(cookieName);
const events2 = await storageProvider2.get(eventsKey);
checker2.checkUserSession(userSession2);
checker2.check(events2?.length === 0, 'events');

Alert.alert(`\
First migration: ${
checker1.errors.length === 0 ? 'Success' : checker1.errors.join(', ')
}
Second migration: ${
checker2.errors.length === 0 ? 'Success' : checker2.errors.join(', ')
}
`);
}

export default App;
6 changes: 6 additions & 0 deletions examples/react-native/legacyDataMigration/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

gem 'cocoapods', '~> 1.12'
133 changes: 133 additions & 0 deletions examples/react-native/legacyDataMigration/MigrationChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {Event, UserSession} from '@amplitude/analytics-types';

type LegacyEvent = {
event_id: number;
event_type: string;
time: number;
insert_id: string;
};

const legacyDeviceId = '22833898-c487-4536-b213-40f207abdce0R';
const legacyUserId = 'react-native-user-legacy';
const legacySessionId = 3684219150343;
const legacyEvents: LegacyEvent[] = [
{
event_id: 1,
event_type: '$identify',
time: 1684219150343,
insert_id: 'be09ecba-83f7-444a-aba0-fe1f529a3716',
},
{
event_id: 2,
event_type: '$identify',
time: 1684219150344,
insert_id: '0894387e-e923-423b-9feb-086ba8cb2cfa',
},
{
event_id: 1,
event_type: '$identify',
time: 1684219150358,
insert_id: '1a14d057-8a12-40bb-8217-2d62dd08a525',
},
{
event_id: 2,
event_type: '$identify',
time: 1684219150359,
insert_id: 'b115a299-4cc6-495b-8e4e-c2ce6f244be9',
},
{
event_id: 1,
event_type: 'legacy event 1',
time: 1684219150354,
insert_id: 'd6eff10b-9cd4-45d7-85cb-c81cb6cb8b2e',
},
{
event_id: 2,
event_type: 'legacy event 2',
time: 1684219150355,
insert_id: '7b4c5c13-6fdc-4931-9ba1-e4efdf346ee0',
},
];

export default class MigrationChecker {
errors: string[] = [];

constructor(private readonly version: 'v4' | 'v3' | 'vMissing') {}

checkUserSession(userSession: UserSession | undefined) {
if (userSession === undefined) {
this.check(false, 'userSession');
return;
}

if (this.version === 'v4' || this.version === 'v3') {
this.check(userSession.deviceId === legacyDeviceId, 'deviceId');
this.check(userSession.userId === legacyUserId, 'userId');
this.check(userSession.sessionId === legacySessionId, 'sessionId');
this.check(userSession.lastEventId === 2, 'lastEventId');
} else {
this.check(userSession.deviceId !== legacyDeviceId, 'deviceId');
this.check(userSession.userId === undefined, 'userId');
this.check(userSession.sessionId !== legacySessionId, 'sessionId');
this.check(userSession.lastEventId === undefined, 'lastEventId');
}
}

checkEvents(events: Event[] | undefined) {
if (events === undefined) {
this.check(false, 'events');
return;
}

if (this.version === 'v4') {
this.compareEvents(events, legacyEvents);
} else if (this.version === 'v3') {
this.compareEvents(events, [
...legacyEvents.slice(0, 2),
...legacyEvents.slice(4),
]);
} else {
this.compareEvents(events, []);
}
}

private compareEvents(events: Event[], expectedEvents: LegacyEvent[]) {
if (events.length !== expectedEvents.length) {
this.check(false, 'events.length');
return;
}

events.forEach((event, i) => {
const eventPrefix = `events[${i}]`;

this.check(
event.event_id === expectedEvents[i].event_id,
`${eventPrefix}.event_id`,
);
this.check(
event.event_type === expectedEvents[i].event_type,
`${eventPrefix}.event_type`,
);
this.check(event.time === expectedEvents[i].time, `${eventPrefix}.time`);
this.check(
event.insert_id === expectedEvents[i].insert_id,
`${eventPrefix}.insert_id`,
);
this.check(
event.library === 'amplitude-react-native/2.17.1',
`${eventPrefix}.library`,
);
this.check(
event.device_id === legacyDeviceId,
`${eventPrefix}.device_id`,
);
this.check(event.user_id === legacyUserId, `${eventPrefix}.user_id`);
});
}

check(assert: boolean, error: string) {
if (!assert) {
this.errors.push(error);
}
}
}
Loading