Przeglądaj źródła

Merge pull request #5460 from overleaf/ab-skip-invalid-identify

Skip identify event when analyticsId is invalid

GitOrigin-RevId: 1fd9c54f59ad0b6196875f9826021e95752eddf0
Alexandre Bourdin 4 lat temu
rodzic
commit
121ee4b72e

+ 3 - 1
services/web/app/src/Features/Analytics/AnalyticsManager.js

@@ -14,8 +14,10 @@ const analyticsUserPropertiesQueue = Queues.getAnalyticsUserPropertiesQueue()
 
 const ONE_MINUTE_MS = 60 * 1000
 
+const UUID_REGEXP = /^[\w]{8}(-[\w]{4}){3}-[\w]{12}$/
+
 function identifyUser(userId, analyticsId, isNewUser) {
-  if (!userId || !analyticsId || userId.toString() === analyticsId.toString()) {
+  if (!userId || !analyticsId || !analyticsId.toString().match(UUID_REGEXP)) {
     return
   }
   if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) {

+ 6 - 8
services/web/test/unit/src/Analytics/AnalyticsManagerTests.js

@@ -81,16 +81,14 @@ describe('AnalyticsManager', function () {
     })
 
     it('analyticsId is missing', function () {
-      this.AnalyticsManager.identifyUser(this.fakeUserId, undefined)
-      sinon.assert.notCalled(this.analyticsEventsQueue.add)
-    })
-
-    it('userId equals analyticsId', function () {
-      this.AnalyticsManager.identifyUser(this.fakeUserId, this.fakeUserId)
+      this.AnalyticsManager.identifyUser(
+        new ObjectID(this.fakeUserId),
+        undefined
+      )
       sinon.assert.notCalled(this.analyticsEventsQueue.add)
     })
 
-    it('Mongo userId equals string userId', function () {
+    it('analyticsId is not a valid UUID', function () {
       this.AnalyticsManager.identifyUser(
         new ObjectID(this.fakeUserId),
         this.fakeUserId
@@ -109,7 +107,7 @@ describe('AnalyticsManager', function () {
 
   describe('queues the appropriate message for', function () {
     it('identifyUser', function () {
-      const analyticsId = '456def'
+      const analyticsId = 'bd101c4c-722f-4204-9e2d-8303e5d9c120'
       this.AnalyticsManager.identifyUser(this.fakeUserId, analyticsId)
       sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'identify', {
         userId: this.fakeUserId,