@optable/web-sdk 0.54.1 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,32 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { determineABTest } from "./abTest";
10
11
  import { fetch } from "../core/network";
11
12
  import { LocalStorage } from "../core/storage";
13
+ import { isBot } from "../addons/botDetection";
12
14
  import * as adcom from "iab-adcom";
13
15
  import { sendTargetingUpdateEvent } from "../core/events/cache-refresh";
14
- // Determine which A/B test (if any) should be used for this request
15
- function determineABTest(abTests) {
16
- if (!abTests || abTests.length === 0) {
17
- return null;
18
- }
19
- // Skip A/B testing if traffic percentage sum exceeds 100%
20
- const totalTrafficPercentage = abTests.reduce((sum, test) => sum + test.trafficPercentage, 0);
21
- if (totalTrafficPercentage > 100) {
22
- console.error(`AB Test Config Error: Traffic Percentage Sum Exceeds 100%`);
23
- return null;
24
- }
25
- // Simple random number 0-99
26
- const bucket = Math.floor(Math.random() * 100);
27
- let cumulative = 0;
28
- for (const test of abTests) {
29
- cumulative += test.trafficPercentage;
30
- if (bucket < cumulative) {
31
- return test;
32
- }
33
- }
34
- return null;
35
- }
16
+ const TARGETING_DONE_KEY = "OPTABLE_TARGETING_DONE";
36
17
  function Targeting(config, req) {
37
18
  return __awaiter(this, void 0, void 0, function* () {
38
19
  var _a;
@@ -80,6 +61,23 @@ function TargetingClearCache(config) {
80
61
  const ls = new LocalStorage(config);
81
62
  ls.clearTargeting();
82
63
  }
64
+ /**
65
+ * Skip targeting for bots by marking targeting as already done,
66
+ * so RTD short-circuits and returns null. No-op for real users.
67
+ * Returns whether the request was identified as a bot.
68
+ */
69
+ export function SkipTargetingForBots() {
70
+ try {
71
+ if (typeof isBot === "function" && isBot()) {
72
+ sessionStorage.setItem(TARGETING_DONE_KEY, "1");
73
+ return true;
74
+ }
75
+ }
76
+ catch (_a) {
77
+ // isBot is unavailable or threw; fall through and treat as a real user.
78
+ }
79
+ return false;
80
+ }
83
81
  function PrebidORTB2(tdata) {
84
82
  var _a, _b;
85
83
  return {
@@ -114,5 +112,5 @@ function TargetingKeyValues(tdata) {
114
112
  }
115
113
  return result;
116
114
  }
117
- export { Targeting, TargetingFromCache, TargetingClearCache, PrebidORTB2, TargetingKeyValues, determineABTest };
115
+ export { Targeting, TargetingFromCache, TargetingClearCache, PrebidORTB2, TargetingKeyValues };
118
116
  export default Targeting;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "homepage": "https://optable.co",
11
11
  "license": "SEE LICENSE IN LICENSE",
12
- "version": "v0.54.1",
12
+ "version": "v0.55.0",
13
13
  "devDependencies": {
14
14
  "@babel/core": "^7.12.3",
15
15
  "@babel/plugin-proposal-class-properties": "^7.12.1",