@builder.io/sdk
Advanced tools
Comparing version 0.0.117 to 0.0.118
@@ -74,2 +74,3 @@ /// <reference types="virtual-dom" /> | ||
static components: Component[]; | ||
static loadGoogleFont(fontName: string): void; | ||
private static incrementalDomLoaded; | ||
@@ -90,2 +91,4 @@ static loadIncrementalDom(): void; | ||
protected isUsed: boolean; | ||
canTrack: boolean; | ||
private canTrack$; | ||
editingMode: boolean; | ||
@@ -109,3 +112,3 @@ editingMode$: BehaviorSubject<boolean>; | ||
}; | ||
init(apiKey: string): this; | ||
init(apiKey: string, canTrack?: boolean): this; | ||
getLocation(): Url; | ||
@@ -119,2 +122,4 @@ getUserAttributes(userAgent?: string): UserAttributes; | ||
requestUrl(url: string): Promise<any>; | ||
readonly env: string; | ||
readonly host: string; | ||
private flushGetContentQueue(usePastQueue?); | ||
@@ -124,2 +129,3 @@ private testCookiePrefix; | ||
private getTestCookie(contentId); | ||
private cookieQueue; | ||
private setTestCookie(contentId, variationId); | ||
@@ -126,0 +132,0 @@ protected getCookie(name: string): any; |
@@ -584,2 +584,3 @@ 'use strict'; | ||
this.isUsed = false; | ||
this.canTrack$ = new BehaviorSubject.BehaviorSubject(true); | ||
this.editingMode$ = new BehaviorSubject.BehaviorSubject(isIframe); | ||
@@ -595,2 +596,3 @@ // TODO: decorator to do this stuff with the get/set (how do with typing too? compiler?) | ||
this.testCookiePrefix = 'builder.tests'; | ||
this.cookieQueue = []; | ||
if (isBrowser) { | ||
@@ -603,3 +605,25 @@ this.bindMessageListeners(); | ||
} | ||
// TODO: on destroy clear subscription | ||
this.canTrack$.subscribe(function (value) { | ||
if (value) { | ||
if (_this.eventsQueue.length) { | ||
_this.throttledClearEventsQueue(); | ||
} | ||
if (_this.cookieQueue.length) { | ||
_this.cookieQueue.forEach(function (item) { | ||
_this.setCookie(item[0], item[1]); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
Builder.loadGoogleFont = function (fontName) { | ||
if (!this.isBrowser) { | ||
return; | ||
} | ||
var link = document.createElement('link'); | ||
link.rel = 'stylesheet'; | ||
link.href = "https://fonts.googleapis.com/css?family=" + fontName.replace(/\s/g, '+'); | ||
document.body.appendChild(link); | ||
}; | ||
Builder.loadIncrementalDom = function () { | ||
@@ -734,2 +758,14 @@ if (!this.isBrowser || this.incrementalDomLoaded) { | ||
}; | ||
Object.defineProperty(Builder.prototype, "canTrack", { | ||
get: function () { | ||
return this.canTrack$.value; | ||
}, | ||
set: function (canTrack) { | ||
if (this.canTrack !== canTrack) { | ||
this.canTrack$.next(canTrack); | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Builder.prototype, "editingMode", { | ||
@@ -764,2 +800,3 @@ get: function () { | ||
if (properties === void 0) { properties = {}; } | ||
// TODO: queue up track requests and fire them off when canTrack set to true - otherwise may get lots of clicks with no impressions | ||
if (isIframe || !isBrowser) { | ||
@@ -773,3 +810,5 @@ return; | ||
}); | ||
this.throttledClearEventsQueue(); | ||
if (this.canTrack) { | ||
this.throttledClearEventsQueue(); | ||
} | ||
}; | ||
@@ -919,3 +958,4 @@ Builder.prototype.trackImpression = function (contentId, variationId) { | ||
}; | ||
Builder.prototype.init = function (apiKey) { | ||
Builder.prototype.init = function (apiKey, canTrack) { | ||
if (canTrack === void 0) { canTrack = true; } | ||
this.apiKey = apiKey; | ||
@@ -989,2 +1029,18 @@ return this; | ||
}; | ||
Object.defineProperty(Builder.prototype, "env", { | ||
get: function () { | ||
// builder.env query param, hash, cookie | ||
return 'prod'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Builder.prototype, "host", { | ||
get: function () { | ||
// TODO: how test images.... | ||
return this.env === 'local' ? 'http://localhost:5000' : 'https://builder.io'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Builder.prototype.flushGetContentQueue = function (usePastQueue) { | ||
@@ -1087,2 +1143,6 @@ var _this = this; | ||
Builder.prototype.setTestCookie = function (contentId, variationId) { | ||
if (!this.canTrack) { | ||
this.cookieQueue.push([contentId, variationId]); | ||
return; | ||
} | ||
return this.setCookie(this.testCookiePrefix + "." + contentId, variationId, { | ||
@@ -1089,0 +1149,0 @@ expires: 30, |
@@ -578,2 +578,3 @@ import uniqueSelector from 'unique-selector'; | ||
this.isUsed = false; | ||
this.canTrack$ = new BehaviorSubject(true); | ||
this.editingMode$ = new BehaviorSubject(isIframe); | ||
@@ -589,2 +590,3 @@ // TODO: decorator to do this stuff with the get/set (how do with typing too? compiler?) | ||
this.testCookiePrefix = 'builder.tests'; | ||
this.cookieQueue = []; | ||
if (isBrowser) { | ||
@@ -597,3 +599,25 @@ this.bindMessageListeners(); | ||
} | ||
// TODO: on destroy clear subscription | ||
this.canTrack$.subscribe(function (value) { | ||
if (value) { | ||
if (_this.eventsQueue.length) { | ||
_this.throttledClearEventsQueue(); | ||
} | ||
if (_this.cookieQueue.length) { | ||
_this.cookieQueue.forEach(function (item) { | ||
_this.setCookie(item[0], item[1]); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
Builder.loadGoogleFont = function (fontName) { | ||
if (!this.isBrowser) { | ||
return; | ||
} | ||
var link = document.createElement('link'); | ||
link.rel = 'stylesheet'; | ||
link.href = "https://fonts.googleapis.com/css?family=" + fontName.replace(/\s/g, '+'); | ||
document.body.appendChild(link); | ||
}; | ||
Builder.loadIncrementalDom = function () { | ||
@@ -728,2 +752,14 @@ if (!this.isBrowser || this.incrementalDomLoaded) { | ||
}; | ||
Object.defineProperty(Builder.prototype, "canTrack", { | ||
get: function () { | ||
return this.canTrack$.value; | ||
}, | ||
set: function (canTrack) { | ||
if (this.canTrack !== canTrack) { | ||
this.canTrack$.next(canTrack); | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Builder.prototype, "editingMode", { | ||
@@ -758,2 +794,3 @@ get: function () { | ||
if (properties === void 0) { properties = {}; } | ||
// TODO: queue up track requests and fire them off when canTrack set to true - otherwise may get lots of clicks with no impressions | ||
if (isIframe || !isBrowser) { | ||
@@ -767,3 +804,5 @@ return; | ||
}); | ||
this.throttledClearEventsQueue(); | ||
if (this.canTrack) { | ||
this.throttledClearEventsQueue(); | ||
} | ||
}; | ||
@@ -913,3 +952,4 @@ Builder.prototype.trackImpression = function (contentId, variationId) { | ||
}; | ||
Builder.prototype.init = function (apiKey) { | ||
Builder.prototype.init = function (apiKey, canTrack) { | ||
if (canTrack === void 0) { canTrack = true; } | ||
this.apiKey = apiKey; | ||
@@ -983,2 +1023,18 @@ return this; | ||
}; | ||
Object.defineProperty(Builder.prototype, "env", { | ||
get: function () { | ||
// builder.env query param, hash, cookie | ||
return 'prod'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Builder.prototype, "host", { | ||
get: function () { | ||
// TODO: how test images.... | ||
return this.env === 'local' ? 'http://localhost:5000' : 'https://builder.io'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Builder.prototype.flushGetContentQueue = function (usePastQueue) { | ||
@@ -1081,2 +1137,6 @@ var _this = this; | ||
Builder.prototype.setTestCookie = function (contentId, variationId) { | ||
if (!this.canTrack) { | ||
this.cookieQueue.push([contentId, variationId]); | ||
return; | ||
} | ||
return this.setCookie(this.testCookiePrefix + "." + contentId, variationId, { | ||
@@ -1083,0 +1143,0 @@ expires: 30, |
{ | ||
"name": "@builder.io/sdk", | ||
"version": "0.0.117", | ||
"version": "0.0.118", | ||
"browser": "./dist/index.umd.min.js", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1052194
16136