landing-page-experiments
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -1,76 +0,2 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
export default class { | ||
static getCookie(name) { | ||
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); | ||
if (match) { | ||
return match[2]; | ||
} | ||
} | ||
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) { | ||
sid = Date.now().toString(36) + Math.random().toString(36).substring(2); | ||
this.setCookie(key, sid); | ||
} | ||
return sid; | ||
} | ||
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(); | ||
} | ||
}); | ||
} | ||
static redirectToUrl(url) { | ||
const currentUrl = new URL(window.location.href); | ||
const newUrl = new URL(url, window.location.href); | ||
if (currentUrl.pathname == newUrl.pathname) { | ||
return; | ||
} | ||
window.location.replace(url); | ||
} | ||
static performRedirect(apiKey, experimentName) { | ||
this.getExperimentConfig(apiKey, experimentName) | ||
.then(config => { | ||
var _a; | ||
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); | ||
return; | ||
} | ||
}) | ||
.catch((reason) => { | ||
console.log(reason); | ||
}); | ||
} | ||
} | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StatsigABHelper=e():t.StatsigABHelper=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>o});const o=class{static getCookie(t){const e=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));if(e)return e[2]}static setCookie(t,e){document.cookie=`${t}=${e}; max-age=31536000; path=/`}static getStableID(){const t="statsig_stable_id";let e=this.getCookie(t);return e||(e=Date.now().toString(36)+Math.random().toString(36).substring(2),this.setCookie(t,e)),e}static getExperimentConfig(t,e){return o=this,n=void 0,r=function*(){const o=this.getStableID(),n=yield fetch("https://featuregates.org/v1/get_config",{method:"POST",headers:{"Content-Type":"application/json","statsig-api-key":t},body:JSON.stringify({user:{userId:o,customIDs:{stableID:o}},configName:e})});if(n.ok)return yield n.json()},new((i=void 0)||(i=Promise))((function(t,e){function a(t){try{s(r.next(t))}catch(t){e(t)}}function c(t){try{s(r.throw(t))}catch(t){e(t)}}function s(e){var o;e.done?t(e.value):(o=e.value,o instanceof i?o:new i((function(t){t(o)}))).then(a,c)}s((r=r.apply(o,n||[])).next())}));var o,n,i,r}static redirectToUrl(t){const e=new URL(window.location.href),o=new URL(t,window.location.href);e.pathname!=o.pathname&&window.location.replace(t)}static performRedirect(t,e){this.getExperimentConfig(t,e).then((t=>{var e;const o=null===(e=null==t?void 0:t.value)||void 0===e?void 0:e.page_url;o&&this.redirectToUrl(o)})).catch((t=>{console.log(t)}))}};return e.default})())); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "landing-page-experiments", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Statsig helps run landing page experiments by redirecting users to two or more landing pages based on an ABn Test.", | ||
@@ -8,3 +8,3 @@ "jsdelivr": "dist/index.js", | ||
"scripts": { | ||
"prepare": "rm -rf build/ && rm -rf dist/ && tsc", | ||
"prepare": "rm -rf dist/ && npm run build", | ||
"prepublish": "npm run build", | ||
@@ -11,0 +11,0 @@ "build": "webpack", |
Sorry, the diff of this file is not supported yet
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
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
11659
109