UNPKG

@embrace-io/web-sdk

Version:
31 lines (30 loc) 1.25 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); //#region src/utils/isDeviceIdEnabled.ts const DIGITS = 6; /** * Determines whether a deviceId is enabled for the given pctEnabled. This is achieved * by taking a normalized hex value from the last 6 digits of the device ID, and comparing * it against the enabled percentage. This ensures that devices are consistently in a given * group for beta functionality. * * This can be used to: * - Select sample devices for telemetry collection * - Enable/disable features for a percentage of users * * The normalized device ID has 16^6 possibilities (roughly 1.6m) which should be sufficient * granularity for our needs. */ const isDeviceIdEnabled = (deviceId, pctEnabled) => { if (!pctEnabled || pctEnabled <= 0 || pctEnabled > 100) return false; return pctEnabled >= getNormalizedDeviceId(deviceId); }; const getNormalizedDeviceId = (deviceId) => { if (deviceId.length < DIGITS) return 0; const finalChars = deviceId.slice(-6); const radix = 16; return parseInt(finalChars, radix) / (radix ** DIGITS - 1) * 100; }; //#endregion exports.getNormalizedDeviceId = getNormalizedDeviceId; exports.isDeviceIdEnabled = isDeviceIdEnabled; //# sourceMappingURL=isDeviceIdEnabled.cjs.map