Просмотр исходного кода

Merge pull request #26349 from overleaf/rh-cio-dashboard-assignment

Assign customer.io split test on projects dashboard

GitOrigin-RevId: 78a21bce31262db15f9701abc0599b44b9023ad2
roo hutton 1 год назад
Родитель
Сommit
6d7b13ac18
1 измененных файлов с 39 добавлено и 8 удалено
  1. 39 8
      services/web/app/src/Features/Project/ProjectListController.mjs

+ 39 - 8
services/web/app/src/Features/Project/ProjectListController.mjs

@@ -29,6 +29,7 @@ import TutorialHandler from '../Tutorial/TutorialHandler.js'
 import SubscriptionHelper from '../Subscription/SubscriptionHelper.js'
 import PermissionsManager from '../Authorization/PermissionsManager.js'
 import SubscriptionLocator from '../Subscription/SubscriptionLocator.js'
+import AnalyticsManager from '../Analytics/AnalyticsManager.js'
 
 /**
  * @import { GetProjectsRequest, GetProjectsResponse, AllUsersProjects, MongoProject } from "./types"
@@ -423,14 +424,44 @@ async function projectListPage(req, res, next) {
     showAiAssistNotification = await _showAiAssistNotification(user)
   }
 
-  const customerIoEnabled =
-    await SplitTestHandler.promises.hasUserBeenAssignedToVariant(
-      req,
-      userId,
-      'customer-io-trial-conversion',
-      'enabled',
-      true
-    )
+  const affiliations = userAffiliations || []
+  const inEnterpriseCommons = affiliations.some(
+    affiliation => affiliation.institution?.enterpriseCommons
+  )
+
+  // customer.io: Premium nudge experiment
+  // Only do customer-io-trial-conversion assignment for users not in India/China and not in group/commons
+  let customerIoEnabled = false
+  if (!userIsMemberOfGroupSubscription && !inEnterpriseCommons) {
+    try {
+      const ip = req.ip
+      const { countryCode } = await GeoIpLookup.promises.getCurrencyCode(ip)
+      const excludedCountries = ['IN', 'CN']
+
+      if (!excludedCountries.includes(countryCode)) {
+        const cioAssignment =
+          await SplitTestHandler.promises.getAssignmentForUser(
+            userId,
+            'customer-io-trial-conversion'
+          )
+        if (cioAssignment.variant === 'enabled') {
+          customerIoEnabled = true
+          AnalyticsManager.setUserPropertyForUserInBackground(
+            userId,
+            'customer-io-integration',
+            true
+          )
+        }
+      }
+    } catch (err) {
+      logger.error(
+        { err },
+        'Error checking geo location for customer-io-trial-conversion'
+      )
+      // Fallback to not enabled if geoip fails
+      customerIoEnabled = false
+    }
+  }
 
   res.render('project/list-react', {
     title: 'your_projects',