landing-page-experiments
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,45 +10,15 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var default_1 = /** @class */ (function () { | ||
function default_1() { | ||
} | ||
default_1.getCookie = function (name) { | ||
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); | ||
export default class { | ||
static getCookie(name) { | ||
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); | ||
if (match) { | ||
return match[2]; | ||
} | ||
}; | ||
default_1.setCookie = function (name, value) { | ||
document.cookie = "".concat(name, "=").concat(value, "; max-age=31536000; path=/"); | ||
}; | ||
default_1.getStableID = function () { | ||
var key = 'statsig_stable_id'; | ||
var sid = this.getCookie(key); | ||
} | ||
static setCookie(name, value) { | ||
document.cookie = `${name}=${value}; max-age=31536000; path=/`; | ||
} | ||
static getStableID() { | ||
const key = 'statsig_stable_id'; | ||
let sid = this.getCookie(key); | ||
if (!sid) { | ||
@@ -60,39 +29,30 @@ sid = Date.now().toString(36) + Math.random().toString(36).substring(2); | ||
return sid; | ||
}; | ||
default_1.getExperimentConfig = function (apiKey, experimentName) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var sid, resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
sid = this.getStableID(); | ||
return [4 /*yield*/, fetch('https://featuregates.org/v1/get_config', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'statsig-api-key': apiKey, | ||
}, | ||
body: JSON.stringify({ | ||
user: { | ||
userId: sid, | ||
customIDs: { | ||
stableID: sid, | ||
} | ||
}, | ||
configName: experimentName, | ||
}), | ||
})]; | ||
case 1: | ||
resp = _a.sent(); | ||
if (!resp.ok) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, resp.json()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
} | ||
static getExperimentConfig(apiKey, experimentName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const sid = this.getStableID(); | ||
const resp = yield fetch('https://featuregates.org/v1/get_config', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'statsig-api-key': apiKey, | ||
}, | ||
body: JSON.stringify({ | ||
user: { | ||
userId: sid, | ||
customIDs: { | ||
stableID: sid, | ||
} | ||
}, | ||
configName: experimentName, | ||
}), | ||
}); | ||
if (resp.ok) { | ||
return yield resp.json(); | ||
} | ||
}); | ||
}; | ||
default_1.redirectToUrl = function (url) { | ||
var currentUrl = new URL(window.location.href); | ||
var newUrl = new URL(url, window.location.href); | ||
} | ||
static redirectToUrl(url) { | ||
const currentUrl = new URL(window.location.href); | ||
const newUrl = new URL(url, window.location.href); | ||
if (currentUrl.pathname == newUrl.pathname) { | ||
@@ -102,20 +62,18 @@ return; | ||
window.location.replace(url); | ||
}; | ||
default_1.performRedirect = function (apiKey, experimentName) { | ||
var _this = this; | ||
} | ||
static performRedirect(apiKey, experimentName) { | ||
this.getExperimentConfig(apiKey, experimentName) | ||
.then(function (config) { | ||
.then(config => { | ||
var _a; | ||
var url = (_a = config === null || config === void 0 ? void 0 : config.value) === null || _a === void 0 ? void 0 : _a.page_url; | ||
const url = (_a = config === null || config === void 0 ? void 0 : config.value) === null || _a === void 0 ? void 0 : _a.page_url; | ||
if (url) { | ||
_this.redirectToUrl(url); | ||
this.redirectToUrl(url); | ||
return; | ||
} | ||
}) | ||
.catch(function (reason) { | ||
.catch((reason) => { | ||
console.log(reason); | ||
}); | ||
}; | ||
return default_1; | ||
}()); | ||
exports.default = default_1; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "landing-page-experiments", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Statsig helps run landing page experiments by redirecting users to two or more landing pages based on an ABn Test.", | ||
@@ -8,3 +8,6 @@ "jsdelivr": "dist/index.js", | ||
"scripts": { | ||
"prepare": "rm -rf build/ && rm -rf dist/ && tsc" | ||
"prepare": "rm -rf build/ && rm -rf dist/ && tsc", | ||
"prepublish": "npm run build", | ||
"build": "webpack", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
@@ -15,3 +18,3 @@ "repository": { | ||
}, | ||
"author": "Statsig, Inc.", | ||
"author": "", | ||
"license": "ISC", | ||
@@ -18,0 +21,0 @@ "bugs": { |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"sourceMap": false, | ||
"esModuleInterop": true, | ||
"allowJs": true, | ||
"checkJs": false, | ||
"declaration": false, | ||
"skipLibCheck": true, | ||
"moduleResolution": "node" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": [ | ||
"node_modules", | ||
"typings", | ||
"src/__tests__/*", | ||
"src/utils/__tests__/*", | ||
"dist", | ||
"build" | ||
] | ||
"lib": ["es2015"] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
9626
177
1
1