feat: create Segment analytics implementation + use geo-localization proxy (Batch 2 of 4)#7520
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
- update metrics class - extract utils - add tests - patch Segment SDK to handle proxy required content type
and updated unit tests
8209e95 to
6dd56d4
Compare
|
Updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring: Next stepsTake a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with |
|
@SocketSecurity ignore @segment/tsub@2.0.0 I verified the said commit and it's just a package version fix |
fac08ff to
6b7f537
Compare
6b7f537 to
ad17b38
Compare
and fix bug and format
and add comment
|
@SocketSecurity ignore-all |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## feat/batch_1129_segment #7520 +/- ##
===========================================================
- Coverage 37.46% 36.80% -0.67%
===========================================================
Files 1052 1091 +39
Lines 28202 29192 +990
Branches 2517 2680 +163
===========================================================
+ Hits 10566 10743 +177
- Misses 17037 17839 +802
- Partials 599 610 +11 ☔ View full report in Codecov by Sentry. |
…_metrics_system # Conflicts: # app/components/Nav/App/index.js
91aeb75 to
1002dd5
Compare
1002dd5 to
854b506
Compare
add tests add delete date getter
81db34f to
62ed6fa
Compare
…_metrics_system # Conflicts: # ios/Podfile.lock
and remove useless test
| * TODO: this is a temporary placeholder implementation. | ||
| * This #createSegmentDeleteRegulation method is currently not testable | ||
| * because Segment delete endpoint proxy is not ready to use. | ||
| * The implementation is mock tested. | ||
| * Real work on this delete feature will be done in a next PR in this batch. | ||
| */ | ||
|
|
||
| /** | ||
| * generate a new delete regulation for the user. | ||
| * This is necessary to respect the GDPR and CCPA regulations. | ||
| * Check Segment documentation for more information. | ||
| * https://segment.com/docs/privacy/user-deletion-and-suppression/ | ||
| */ | ||
| #createSegmentDeleteRegulation = async (): Promise<{ | ||
| #createDeleteRegulation = async (): Promise<{ | ||
| status: string; | ||
| error?: string; | ||
| }> => { | ||
| const segmentToken = process.env.SEGMENT_DELETION_API_KEY; | ||
| const regulationType = 'DELETE_ONLY'; | ||
| try { | ||
| const response = await axios({ | ||
| url: SEGMENT_REGULATIONS_ENDPOINT, | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/vnd.segment.v1alpha+json', | ||
| Authorization: `Bearer ${segmentToken}`, | ||
| }, | ||
| data: JSON.stringify({ | ||
| regulationType, | ||
| subjectType: 'USER_ID', | ||
| subjectIds: [this.#metametricsId], | ||
| }), | ||
| }); | ||
| const { result, status } = response as any; | ||
|
|
||
| if (status === '200') { | ||
| const { regulateId } = result.data; | ||
| await this.#storeDeleteRegulationId(regulateId); | ||
| await this.#storeDeleteRegulationCreationDate(); | ||
| return { status: DataDeleteResponseStatus.ok }; | ||
| } | ||
|
|
||
| return { status: DataDeleteResponseStatus.error }; | ||
| } catch (error: any) { | ||
| Logger.error(error, 'Analytics Deletion Task Error'); | ||
| return { status: DataDeleteResponseStatus.error, error }; | ||
| } | ||
| }; | ||
|
|
||
| // PUBLIC METHODS | ||
| }> => ({ | ||
| status: DataDeleteResponseStatus.error, | ||
| error: 'Analytics Deletion Task Error', | ||
| }); | ||
| // => { | ||
| // const segmentToken = process.env.SEGMENT_DELETION_API_KEY; | ||
| // const regulationType = 'DELETE_ONLY'; | ||
| // try { | ||
| // const response = await axios({ | ||
| // url: SEGMENT_REGULATIONS_ENDPOINT, | ||
| // method: 'POST', | ||
| // headers: { | ||
| // 'Content-Type': 'application/vnd.segment.v1alpha+json', | ||
| // Authorization: `Bearer ${segmentToken}`, | ||
| // }, | ||
| // data: JSON.stringify({ | ||
| // regulationType, | ||
| // subjectType: 'USER_ID', | ||
| // subjectIds: [this.metametricsId], | ||
| // }), | ||
| // }); | ||
| // const { data } = response as any; | ||
| // const { regulateId } = data; | ||
| // await this.#storeDeleteRegulationId(regulateId); | ||
| // await this.#storeDeleteRegulationCreationDate(); | ||
| // return { status: DataDeleteResponseStatus.ok }; | ||
| // } catch (error: any) { | ||
| // Logger.error(error, 'Analytics Deletion Task Error'); | ||
| // return { | ||
| // status: DataDeleteResponseStatus.error, | ||
| // error: 'Analytics Deletion Task Error', | ||
| // }; | ||
| // } | ||
| // }; |
There was a problem hiding this comment.
In order to unblock this PR, this is to be implemented in another PR in the batch as we don't have the proxy yet.
…_metrics_system # Conflicts: # ios/Podfile.lock
|
Kudos, SonarCloud Quality Gate passed! |








Description
IMPORTANT
This PR contains a placeholder for the user metrics deletion request. This is to be implemented in a next PR in this batch but made fake here on purpose to prevent blocking this PR progress. See the following placeholder code and comment in this PR.
NOTE: We discussed splitting this PR to extract the SDK patch in its own PR. But I would like to first try in only one PR, first because it's not so big, just 11 files, we've seen worse, but mostly because looking at the patch without the context of the MetaMetrics class seems strange and more complicated to me and could lead to mistakes or questions that are answered by the Metametrics code itself.
However, if you believe I should absolutely make it in a separate PR, I will do it. Thanks.
Related issues
Fixes MetaMask/mobile-planning#1222
Manual testing steps
Only unit tests, manual testing will be available for next step in this batch of work.
Screenshots/Recordings
Bellow it no screenshot but the data received by Segment that we can see on the monitoring dev website.
Before
NA
After
Two event criteria:
Example of anonymous event because user is not identified:
{ "context": { "library": { "name": "source-functions", "version": "1.0.0" }, "location": { "api_processing_time_ms": 580, "country_code": "FR", "region": "NOR", "timezone": "Europe/Paris" } }, "event": "183637normal anonymous event", "integrations": {}, "messageId": "8f0e9b2e-a6ab-4b3f-922d-731932cce1a4", "originalTimestamp": "2023-11-16T17:36:45.43083525Z", "properties": { "applicationVersion": "7.10.0", "currentBuildNumber": "1187", "deviceBrand": "Apple", "operatingSystemVersion": "17.0.1", "platform": "ios" }, "receivedAt": "2023-11-16T17:36:45.431Z", "sentAt": "2023-11-16T17:36:45.430Z", "timestamp": "2023-11-16T17:36:45.430Z", "type": "track", "userId": "0x0000000000000000", "writeKey": "REDACTED" }Example of anonymous event because user is not identified AND we don't want to know the details:
{ "context": { "library": { "name": "source-functions", "version": "1.0.0" }, "location": { "api_processing_time_ms": 580, "country_code": "FR", "region": "NOR", "timezone": "Europe/Paris" } }, "event": "183637anonymous anonymous event", "integrations": {}, "messageId": "daa2a578-4778-49fb-91d2-389c864fb5e5", "originalTimestamp": "2023-11-16T17:36:45.430876388Z", "properties": {}, "receivedAt": "2023-11-16T17:36:45.431Z", "sentAt": "2023-11-16T17:36:45.430Z", "timestamp": "2023-11-16T17:36:45.430Z", "type": "track", "userId": "0x0000000000000000", "writeKey": "REDACTED" }Then the user can identify:
{ "context": { "library": { "name": "source-functions", "version": "1.0.0" }, "location": { "api_processing_time_ms": 0, "country_code": "FR", "region": "NOR", "timezone": "Europe/Paris" } }, "integrations": {}, "messageId": "72361f1f-3d8a-4b9a-97e1-7b01b457c4df", "originalTimestamp": "2023-11-16T17:37:13.309513172Z", "receivedAt": "2023-11-16T17:37:13.310Z", "sentAt": "2023-11-16T17:37:13.309Z", "timestamp": "2023-11-16T17:37:13.310Z", "traits": { "testtime": "183637" }, "type": "identify", "userId": "0x7fb47bfe4e25c4e70097365f61838cfff275191e61f85262a51dc59fe52123de", "writeKey": "REDACTED" }and once identified, the events can still be sent anonymously or not depending if we have to know the details or not:
We know what but not who:
{ "context": { "library": { "name": "source-functions", "version": "1.0.0" }, "location": { "api_processing_time_ms": 0, "country_code": "FR", "region": "NOR", "timezone": "Europe/Paris" } }, "event": "183637delayed identified anonymous event", "integrations": {}, "messageId": "4031820c-e2b0-4bfa-ae47-ccdf77a54d64", "originalTimestamp": "2023-11-16T17:37:13.30954482Z", "properties": { "applicationVersion": "7.10.0", "currentBuildNumber": "1187", "deviceBrand": "Apple", "operatingSystemVersion": "17.0.1", "platform": "ios" }, "receivedAt": "2023-11-16T17:37:13.310Z", "sentAt": "2023-11-16T17:37:13.309Z", "timestamp": "2023-11-16T17:37:13.310Z", "type": "track", "userId": "0x0000000000000000", "writeKey": "REDACTED" }or we know who but not what:
{ "context": { "library": { "name": "source-functions", "version": "1.0.0" }, "location": { "api_processing_time_ms": 0, "country_code": "FR", "region": "NOR", "timezone": "Europe/Paris" } }, "event": "183637delayed identified anonymous event", "integrations": {}, "messageId": "5076ef49-a852-4d23-8331-99ca81ee0e92", "originalTimestamp": "2023-11-16T17:37:13.309556282Z", "properties": {}, "receivedAt": "2023-11-16T17:37:13.310Z", "sentAt": "2023-11-16T17:37:13.309Z", "timestamp": "2023-11-16T17:37:13.310Z", "type": "track", "userId": "0x7fb47bfe4e25c4e70097365f61838cfff275191e61f85262a51dc59fe52123de", "writeKey": "REDACTED" }Pre-merge author checklist
Pre-merge reviewer checklist