mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #4001 from overleaf/ab-hash-split-test
Add hashing to compute the user's percentile in a split test GitOrigin-RevId: 94302cd1c0ab9e9075a506096b4f36ba50b9b7fa
This commit is contained in:
parent
8faae673b4
commit
87b3654bff
3 changed files with 15 additions and 5 deletions
|
@ -30,6 +30,7 @@ const MONTH_NAMES = [
|
|||
'November',
|
||||
'December',
|
||||
]
|
||||
const EXAMPLE_PROJECT_SPLITTEST_ID = 'example-project-v2'
|
||||
|
||||
async function createBlankProject(ownerId, projectName, attributes = {}) {
|
||||
const isImport = attributes && attributes.overleaf
|
||||
|
@ -72,7 +73,7 @@ async function createExampleProject(ownerId, projectName) {
|
|||
|
||||
const testSegmentation = SplitTestHandler.getTestSegmentation(
|
||||
ownerId,
|
||||
'example-project'
|
||||
EXAMPLE_PROJECT_SPLITTEST_ID
|
||||
)
|
||||
|
||||
if (testSegmentation.variant === 'example-frog') {
|
||||
|
@ -84,7 +85,7 @@ async function createExampleProject(ownerId, projectName) {
|
|||
if (testSegmentation.enabled) {
|
||||
AnalyticsManager.recordEvent(ownerId, 'project-created', {
|
||||
projectId: project._id,
|
||||
splitTestId: 'example-project',
|
||||
splitTestId: EXAMPLE_PROJECT_SPLITTEST_ID,
|
||||
splitTestVariantId: testSegmentation.variant,
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const Settings = require('settings-sharelatex')
|
||||
const _ = require('lodash')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const crypto = require('crypto')
|
||||
const OError = require('@overleaf/o-error')
|
||||
|
||||
const ACTIVE_SPLIT_TESTS = []
|
||||
|
@ -34,7 +34,7 @@ for (const splitTest of Settings.splitTests) {
|
|||
function getTestSegmentation(userId, splitTestId) {
|
||||
const splitTest = _.find(ACTIVE_SPLIT_TESTS, ['id', splitTestId])
|
||||
if (splitTest) {
|
||||
let userIdAsPercentile = (ObjectId(userId).getTimestamp() / 1000) % 100
|
||||
let userIdAsPercentile = _getPercentile(userId, splitTestId)
|
||||
for (const variant of splitTest.variants) {
|
||||
if (userIdAsPercentile < variant.rolloutPercent) {
|
||||
return {
|
||||
|
@ -55,6 +55,15 @@ function getTestSegmentation(userId, splitTestId) {
|
|||
}
|
||||
}
|
||||
|
||||
function _getPercentile(userId, splitTestId) {
|
||||
const hash = crypto
|
||||
.createHash('md5')
|
||||
.update(userId + splitTestId)
|
||||
.digest('hex')
|
||||
const hashPrefix = hash.substr(0, 8)
|
||||
return Math.floor((parseInt(hashPrefix, 16) / 0xffffffff) * 100)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTestSegmentation,
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ module.exports = settings =
|
|||
|
||||
splitTests: [
|
||||
{
|
||||
id: 'example-project'
|
||||
id: 'example-project-v2'
|
||||
active: process.env['SPLITTEST_EXAMPLE_PROJECT_ACTIVE'] == 'true'
|
||||
variants: [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue