saasco-sdk 0.2.4 → 0.2.5
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.
- package/README.md +974 -0
- package/dist/index.cjs +168 -117
- package/dist/index.d.cts +21 -42
- package/dist/index.d.ts +21 -42
- package/dist/index.js +168 -117
- package/dist/support.cjs +1411 -829
- package/dist/support.d.cts +20 -9
- package/dist/support.d.ts +20 -9
- package/dist/support.js +1439 -857
- package/package.json +21 -1
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var import_psl = require("psl");
|
|
39
39
|
|
|
40
40
|
// package.json
|
|
41
|
-
var version = "0.2.
|
|
41
|
+
var version = "0.2.5";
|
|
42
42
|
|
|
43
43
|
// src/lib/timezones.ts
|
|
44
44
|
var timezones = {
|
|
@@ -487,6 +487,9 @@ var AnalyticsLogger = class {
|
|
|
487
487
|
constructor(config) {
|
|
488
488
|
this.config = config;
|
|
489
489
|
}
|
|
490
|
+
setLevel(level) {
|
|
491
|
+
this.config.level = level;
|
|
492
|
+
}
|
|
490
493
|
debug(...args) {
|
|
491
494
|
if (this.config.level < 3 /* DEBUG */) {
|
|
492
495
|
return;
|
|
@@ -567,9 +570,34 @@ function getIntegrationLoggerLevel(integrationName, debug) {
|
|
|
567
570
|
}
|
|
568
571
|
|
|
569
572
|
// src/lib/utils/uuid.ts
|
|
570
|
-
var
|
|
573
|
+
var HEX = [];
|
|
574
|
+
for (let i = 0; i < 256; i++) {
|
|
575
|
+
HEX[i] = (i + 256).toString(16).slice(1);
|
|
576
|
+
}
|
|
571
577
|
function uuid() {
|
|
572
|
-
|
|
578
|
+
const bytes = randomBytes(16);
|
|
579
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
580
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
581
|
+
let out = "";
|
|
582
|
+
for (let i = 0; i < 16; i++) {
|
|
583
|
+
out += HEX[bytes[i]];
|
|
584
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) {
|
|
585
|
+
out += "-";
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return out;
|
|
589
|
+
}
|
|
590
|
+
function randomBytes(length) {
|
|
591
|
+
const bytes = new Uint8Array(length);
|
|
592
|
+
const webCrypto = globalThis.crypto;
|
|
593
|
+
if (typeof webCrypto?.getRandomValues === "function") {
|
|
594
|
+
webCrypto.getRandomValues(bytes);
|
|
595
|
+
return bytes;
|
|
596
|
+
}
|
|
597
|
+
for (let i = 0; i < length; i++) {
|
|
598
|
+
bytes[i] = Math.random() * 256 | 0;
|
|
599
|
+
}
|
|
600
|
+
return bytes;
|
|
573
601
|
}
|
|
574
602
|
|
|
575
603
|
// src/lib/getBrowserContext.ts
|
|
@@ -1875,6 +1903,41 @@ function normalizeSaascoUrl(url) {
|
|
|
1875
1903
|
return parsed.toString();
|
|
1876
1904
|
}
|
|
1877
1905
|
|
|
1906
|
+
// src/lib/widgetLoader.ts
|
|
1907
|
+
function isEnabledPayload(data2) {
|
|
1908
|
+
return typeof data2 === "object" && data2 !== null && "enabled" in data2 && data2.enabled === true;
|
|
1909
|
+
}
|
|
1910
|
+
function getUrlOrigin(url) {
|
|
1911
|
+
try {
|
|
1912
|
+
return new URL(
|
|
1913
|
+
url,
|
|
1914
|
+
typeof window === "undefined" ? void 0 : window.location.href
|
|
1915
|
+
).origin;
|
|
1916
|
+
} catch {
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
function isLoaderPresent(fileName, injectedFlag) {
|
|
1920
|
+
return Boolean(
|
|
1921
|
+
injectedFlag || document.querySelector(`script[src*="${fileName}"]`)
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
function appendLoaderScript({
|
|
1925
|
+
attributes,
|
|
1926
|
+
onLoad,
|
|
1927
|
+
src
|
|
1928
|
+
}) {
|
|
1929
|
+
const script = document.createElement("script");
|
|
1930
|
+
script.async = true;
|
|
1931
|
+
script.src = src;
|
|
1932
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
1933
|
+
script.setAttribute(name, value);
|
|
1934
|
+
}
|
|
1935
|
+
if (onLoad) {
|
|
1936
|
+
script.addEventListener("load", onLoad);
|
|
1937
|
+
}
|
|
1938
|
+
(document.body ?? document.head ?? document.documentElement).append(script);
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1878
1941
|
// src/lib/social-proof/storage.ts
|
|
1879
1942
|
var WIDGET_PAYLOAD_PATH = "/api/social-proof/widget";
|
|
1880
1943
|
var SOCIAL_PROOF_LOADER_FILE = "saasco-social-proof-loader.js";
|
|
@@ -1954,17 +2017,16 @@ async function injectSocialProofLoader({
|
|
|
1954
2017
|
return;
|
|
1955
2018
|
}
|
|
1956
2019
|
window.__saascoSocialProofInjected = true;
|
|
1957
|
-
const
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
script.setAttribute("data-projectId", projectId);
|
|
2020
|
+
const attributes = {
|
|
2021
|
+
"data-projectId": projectId
|
|
2022
|
+
};
|
|
1961
2023
|
if (baseUrlOverride !== void 0) {
|
|
1962
|
-
|
|
1963
|
-
"data-base-url",
|
|
1964
|
-
normalizeSaascoBaseUrl(baseUrlOverride)
|
|
1965
|
-
);
|
|
2024
|
+
attributes["data-base-url"] = normalizeSaascoBaseUrl(baseUrlOverride);
|
|
1966
2025
|
}
|
|
1967
|
-
(
|
|
2026
|
+
appendLoaderScript({
|
|
2027
|
+
attributes,
|
|
2028
|
+
src: normalizeSaascoUrl(scriptUrl)
|
|
2029
|
+
});
|
|
1968
2030
|
}
|
|
1969
2031
|
async function shouldInjectSocialProof({
|
|
1970
2032
|
baseUrl,
|
|
@@ -1993,23 +2055,12 @@ async function shouldInjectSocialProof({
|
|
|
1993
2055
|
writeSession(cacheKey, JSON.stringify({ data: data2, fetchedAt: Date.now() }));
|
|
1994
2056
|
return isEnabledPayload(data2);
|
|
1995
2057
|
}
|
|
1996
|
-
function isEnabledPayload(data2) {
|
|
1997
|
-
return typeof data2 === "object" && data2 !== null && data2.enabled === true;
|
|
1998
|
-
}
|
|
1999
2058
|
function isSocialProofLoaderPresent() {
|
|
2000
|
-
return
|
|
2001
|
-
|
|
2059
|
+
return isLoaderPresent(
|
|
2060
|
+
SOCIAL_PROOF_LOADER_FILE,
|
|
2061
|
+
window.__saascoSocialProofInjected
|
|
2002
2062
|
);
|
|
2003
2063
|
}
|
|
2004
|
-
function getUrlOrigin(url) {
|
|
2005
|
-
try {
|
|
2006
|
-
return new URL(
|
|
2007
|
-
url,
|
|
2008
|
-
typeof window === "undefined" ? void 0 : window.location.href
|
|
2009
|
-
).origin;
|
|
2010
|
-
} catch {
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
2064
|
function isSocialProofQaMode() {
|
|
2014
2065
|
if (typeof window === "undefined") {
|
|
2015
2066
|
return false;
|
|
@@ -2024,6 +2075,72 @@ function isSocialProofQaMode() {
|
|
|
2024
2075
|
}
|
|
2025
2076
|
}
|
|
2026
2077
|
|
|
2078
|
+
// src/lib/support/widgetEnabledCheck.ts
|
|
2079
|
+
var SUPPORT_WIDGET_PATH = "/api/support/widget";
|
|
2080
|
+
var SUPPORT_LOADER_FILE = "saasco-support-loader.js";
|
|
2081
|
+
async function injectSupportLoader({
|
|
2082
|
+
baseUrl: baseUrlOverride,
|
|
2083
|
+
onLoad,
|
|
2084
|
+
placeholder,
|
|
2085
|
+
projectId,
|
|
2086
|
+
scriptUrl
|
|
2087
|
+
}) {
|
|
2088
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2089
|
+
return "skipped";
|
|
2090
|
+
}
|
|
2091
|
+
if (isSupportLoaderPresent()) {
|
|
2092
|
+
return "present";
|
|
2093
|
+
}
|
|
2094
|
+
const baseUrl = normalizeSaascoBaseUrl(
|
|
2095
|
+
baseUrlOverride ?? getUrlOrigin(scriptUrl) ?? SAASCO_ORIGIN
|
|
2096
|
+
);
|
|
2097
|
+
const enabled = await shouldInjectSupport({
|
|
2098
|
+
baseUrl,
|
|
2099
|
+
projectId
|
|
2100
|
+
});
|
|
2101
|
+
if (!enabled) {
|
|
2102
|
+
return "skipped";
|
|
2103
|
+
}
|
|
2104
|
+
if (isSupportLoaderPresent()) {
|
|
2105
|
+
return "present";
|
|
2106
|
+
}
|
|
2107
|
+
window.__saascoSupportInjected = true;
|
|
2108
|
+
const attributes = {
|
|
2109
|
+
"data-projectId": projectId
|
|
2110
|
+
};
|
|
2111
|
+
if (baseUrlOverride !== void 0) {
|
|
2112
|
+
attributes["data-base-url"] = normalizeSaascoBaseUrl(baseUrlOverride);
|
|
2113
|
+
}
|
|
2114
|
+
if (placeholder !== void 0) {
|
|
2115
|
+
attributes["data-placeholder"] = placeholder;
|
|
2116
|
+
}
|
|
2117
|
+
appendLoaderScript({
|
|
2118
|
+
attributes,
|
|
2119
|
+
onLoad,
|
|
2120
|
+
src: normalizeSaascoUrl(scriptUrl)
|
|
2121
|
+
});
|
|
2122
|
+
return "injected";
|
|
2123
|
+
}
|
|
2124
|
+
async function shouldInjectSupport({
|
|
2125
|
+
baseUrl,
|
|
2126
|
+
projectId
|
|
2127
|
+
}) {
|
|
2128
|
+
try {
|
|
2129
|
+
const response = await fetch(
|
|
2130
|
+
`${baseUrl}${SUPPORT_WIDGET_PATH}?projectId=${encodeURIComponent(projectId)}`
|
|
2131
|
+
);
|
|
2132
|
+
if (!response.ok) {
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
return isEnabledPayload(await response.json());
|
|
2136
|
+
} catch {
|
|
2137
|
+
return false;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
function isSupportLoaderPresent() {
|
|
2141
|
+
return isLoaderPresent(SUPPORT_LOADER_FILE, window.__saascoSupportInjected);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2027
2144
|
// src/lib/analytics.ts
|
|
2028
2145
|
function getSupportGlobal() {
|
|
2029
2146
|
return window.SaascoSupport;
|
|
@@ -2033,10 +2150,6 @@ var isServer5 = !isBrowser5;
|
|
|
2033
2150
|
var PREF = "saasco-sdk";
|
|
2034
2151
|
var SESSION_DURATION = 1e3 * 60 * 30;
|
|
2035
2152
|
var USER_DURATION = 1e3 * 60 * 60 * 24 * 365;
|
|
2036
|
-
var SUPPORT_ATTR_MAP = {
|
|
2037
|
-
baseUrl: "data-base-url",
|
|
2038
|
-
placeholder: "data-placeholder"
|
|
2039
|
-
};
|
|
2040
2153
|
var data = {};
|
|
2041
2154
|
function getRootDomain(url) {
|
|
2042
2155
|
if (isServer5) {
|
|
@@ -2325,7 +2438,7 @@ var Saasco = class {
|
|
|
2325
2438
|
* @param config Configuration options.
|
|
2326
2439
|
* @param config.projectId The unique identifier for the project.
|
|
2327
2440
|
* @param config.proxy The URL of the proxy server to use, if any.
|
|
2328
|
-
* @param config.autoPageTracking Whether to automatically track page views. Default is
|
|
2441
|
+
* @param config.autoPageTracking Whether to automatically track page views. Default is true.
|
|
2329
2442
|
* @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
|
|
2330
2443
|
* @param config.debug Whether to log debug information. Default is false.
|
|
2331
2444
|
* @param config.trackUrlParams Whether to track URL parameters. Default is true.
|
|
@@ -2401,52 +2514,20 @@ var Saasco = class {
|
|
|
2401
2514
|
);
|
|
2402
2515
|
}
|
|
2403
2516
|
this.initAutoPageTracking();
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
}
|
|
2407
|
-
if (this.config.socialProof?.enabled !== false) {
|
|
2408
|
-
void this.injectSocialProof();
|
|
2409
|
-
}
|
|
2517
|
+
void this.injectSupport();
|
|
2518
|
+
void this.injectSocialProof();
|
|
2410
2519
|
this.isInitialized = true;
|
|
2411
2520
|
}
|
|
2412
2521
|
disableDebug() {
|
|
2413
2522
|
this.logger.info("Debug mode deactivated.");
|
|
2414
2523
|
this.config.debug = false;
|
|
2524
|
+
this.logger.setLevel(getLoggerLevel(this.config));
|
|
2415
2525
|
}
|
|
2416
2526
|
enableDebug() {
|
|
2417
2527
|
this.config.debug = true;
|
|
2528
|
+
this.logger.setLevel(getLoggerLevel(this.config));
|
|
2418
2529
|
this.logger.info("Debug mode activated.");
|
|
2419
2530
|
}
|
|
2420
|
-
/**
|
|
2421
|
-
* Enables and injects the support widget when it was constructed with
|
|
2422
|
-
* `support: { enabled: false }`. Safe to call multiple times.
|
|
2423
|
-
*/
|
|
2424
|
-
enableSupport() {
|
|
2425
|
-
if (!this.config.support) {
|
|
2426
|
-
this.logger.warn(
|
|
2427
|
-
"Support is not configured; enableSupport() was ignored."
|
|
2428
|
-
);
|
|
2429
|
-
return;
|
|
2430
|
-
}
|
|
2431
|
-
this.config.support.enabled = true;
|
|
2432
|
-
this.injectSupport();
|
|
2433
|
-
this.pushSupportIdentity();
|
|
2434
|
-
}
|
|
2435
|
-
/**
|
|
2436
|
-
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
2437
|
-
* `socialProof: { enabled: false }`, or when no `socialProof` block was
|
|
2438
|
-
* passed). Injection still runs the server check, so the loader only
|
|
2439
|
-
* downloads when the project has the app enabled in the dashboard.
|
|
2440
|
-
* Safe to call multiple times — the loader injection is guarded against
|
|
2441
|
-
* double-injection.
|
|
2442
|
-
*/
|
|
2443
|
-
enableSocialProof() {
|
|
2444
|
-
this.config.socialProof = {
|
|
2445
|
-
...this.config.socialProof,
|
|
2446
|
-
enabled: true
|
|
2447
|
-
};
|
|
2448
|
-
void this.injectSocialProof();
|
|
2449
|
-
}
|
|
2450
2531
|
/**
|
|
2451
2532
|
* Initialize third-party integrations
|
|
2452
2533
|
*/
|
|
@@ -2563,7 +2644,7 @@ var Saasco = class {
|
|
|
2563
2644
|
}
|
|
2564
2645
|
/**
|
|
2565
2646
|
* The page method lets you record page views on your website
|
|
2566
|
-
* This records the page title and path and names the event
|
|
2647
|
+
* This records the page title and path and names the event using the reserved name "Page View"
|
|
2567
2648
|
*
|
|
2568
2649
|
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
2569
2650
|
*/
|
|
@@ -2787,51 +2868,25 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2787
2868
|
return this.integrationManager.getStats();
|
|
2788
2869
|
}
|
|
2789
2870
|
/**
|
|
2790
|
-
* Lazily injects the support **loader**
|
|
2791
|
-
*
|
|
2792
|
-
* config as `data-*` attributes. The loader (no React) injects the
|
|
2793
|
-
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
2794
|
-
* double-injection so re-running `init()` is a no-op.
|
|
2871
|
+
* Lazily injects the support **loader** (server-gated). See
|
|
2872
|
+
* {@link injectSupportLoader}. Replays identity once the script loads.
|
|
2795
2873
|
*/
|
|
2796
|
-
injectSupport() {
|
|
2797
|
-
if (!isBrowser5
|
|
2798
|
-
return;
|
|
2799
|
-
}
|
|
2800
|
-
const chat = this.config.support;
|
|
2801
|
-
if (!chat) {
|
|
2802
|
-
return;
|
|
2803
|
-
}
|
|
2804
|
-
if (window.__saascoSupportInjected || document.querySelector('script[src*="saasco-support-loader.js"]')) {
|
|
2805
|
-
return;
|
|
2806
|
-
}
|
|
2807
|
-
const scriptUrl = resolveLoaderScriptUrl(
|
|
2808
|
-
"saasco-support-loader.js",
|
|
2809
|
-
chat.scriptUrl
|
|
2810
|
-
);
|
|
2811
|
-
if (!scriptUrl) {
|
|
2812
|
-
this.logger.warn(
|
|
2813
|
-
"Support is enabled but the loader URL could not be resolved. Pass `support.scriptUrl` pointing at your hosted saasco-support-loader.js (or load the analytics SDK from the CDN)."
|
|
2814
|
-
);
|
|
2874
|
+
async injectSupport() {
|
|
2875
|
+
if (!isBrowser5) {
|
|
2815
2876
|
return;
|
|
2816
2877
|
}
|
|
2817
|
-
|
|
2818
|
-
const
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
script.setAttribute(
|
|
2826
|
-
attr,
|
|
2827
|
-
attr === "data-base-url" ? normalizeSaascoBaseUrl(value) : value
|
|
2828
|
-
);
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
script.addEventListener("load", () => {
|
|
2832
|
-
this.pushSupportIdentity();
|
|
2878
|
+
const { support } = this.config;
|
|
2879
|
+
const scriptUrl = resolveLoaderScriptUrl("saasco-support-loader.js", support?.scriptUrl) ?? `${SAASCO_ORIGIN}/sdk/saasco-support-loader.js`;
|
|
2880
|
+
const result = await injectSupportLoader({
|
|
2881
|
+
baseUrl: support?.baseUrl,
|
|
2882
|
+
onLoad: () => this.pushSupportIdentity(),
|
|
2883
|
+
placeholder: support?.placeholder,
|
|
2884
|
+
projectId: this.config.projectId,
|
|
2885
|
+
scriptUrl
|
|
2833
2886
|
});
|
|
2834
|
-
(
|
|
2887
|
+
if (result === "present") {
|
|
2888
|
+
this.pushSupportIdentity();
|
|
2889
|
+
}
|
|
2835
2890
|
}
|
|
2836
2891
|
/**
|
|
2837
2892
|
* Lazily injects the social-proof loader (server-gated). See
|
|
@@ -2854,27 +2909,23 @@ Request Data: ${JSON.stringify(requestData, null, 2)}`
|
|
|
2854
2909
|
}
|
|
2855
2910
|
/**
|
|
2856
2911
|
* Records the latest CRM identity and forwards it to the support widget.
|
|
2857
|
-
* No-op when support isn't enabled.
|
|
2858
2912
|
*/
|
|
2859
2913
|
updateSupportIdentity(identity) {
|
|
2860
|
-
if (!isBrowser5
|
|
2914
|
+
if (!isBrowser5) {
|
|
2861
2915
|
return;
|
|
2862
2916
|
}
|
|
2863
2917
|
const hasTraits = identity.traits && Object.keys(identity.traits).length > 0;
|
|
2864
2918
|
this.lastSupportIdentity = identity.distinctId || identity.email || hasTraits ? identity : null;
|
|
2865
|
-
if (this.config.support.enabled === false) {
|
|
2866
|
-
return;
|
|
2867
|
-
}
|
|
2868
2919
|
this.pushSupportIdentity();
|
|
2869
2920
|
}
|
|
2870
2921
|
/**
|
|
2871
2922
|
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
2872
2923
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
2873
|
-
* it (same approach as tool registration)
|
|
2874
|
-
*
|
|
2924
|
+
* it (same approach as tool registration). `injectSupport` calls this on
|
|
2925
|
+
* script load (or immediately when the loader is already present).
|
|
2875
2926
|
*/
|
|
2876
2927
|
pushSupportIdentity() {
|
|
2877
|
-
if (!isBrowser5
|
|
2928
|
+
if (!isBrowser5) {
|
|
2878
2929
|
return;
|
|
2879
2930
|
}
|
|
2880
2931
|
const identity = this.lastSupportIdentity ?? {
|
package/dist/index.d.cts
CHANGED
|
@@ -287,17 +287,22 @@ type DoRequestResponse = {
|
|
|
287
287
|
};
|
|
288
288
|
type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
|
|
289
289
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
290
|
+
* Optional config for the support widget. Support is **always available
|
|
291
|
+
* wherever the analytics SDK runs** — you don't need to pass this object at
|
|
292
|
+
* all. Whether the widget actually renders is decided **server-side**: on init
|
|
293
|
+
* the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
|
|
294
|
+
* (`saasco-support-loader.js`) only when the project has the widget enabled
|
|
295
|
+
* in the dashboard, so pages where it's off never download it — and the
|
|
296
|
+
* dashboard toggle controls every install (CDN and npm) uniformly.
|
|
297
|
+
*
|
|
298
|
+
* The loader origin is resolved automatically: the CDN `<script>` origin for
|
|
299
|
+
* CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
|
|
300
|
+
* object only to override those defaults: `baseUrl`/`scriptUrl` point a
|
|
301
|
+
* same-origin, proxied, or self-hosted install at the right origin.
|
|
302
|
+
* The projectId is shared from the analytics config — you never declare it
|
|
303
|
+
* twice.
|
|
297
304
|
*/
|
|
298
305
|
type SupportInit = {
|
|
299
|
-
/** Defaults to `true` when the `support` object is provided. */
|
|
300
|
-
enabled?: boolean;
|
|
301
306
|
/** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
|
|
302
307
|
baseUrl?: string;
|
|
303
308
|
/** Input placeholder for the chat composer. */
|
|
@@ -323,19 +328,11 @@ type SupportInit = {
|
|
|
323
328
|
* The loader + widget-payload origin is resolved automatically: the CDN
|
|
324
329
|
* `<script>` origin for CDN installs, else the public Saasco CDN for
|
|
325
330
|
* npm/bundled installs (which carry no script tag on the page). Pass this object
|
|
326
|
-
* only to override those defaults
|
|
327
|
-
* `data-social-proof-enabled="false"` on the CDN tag) is a client kill-switch
|
|
328
|
-
* that skips the check entirely; `baseUrl`/`scriptUrl` point a same-origin,
|
|
331
|
+
* only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
|
|
329
332
|
* proxied, or self-hosted install at the right origin. The projectId is shared
|
|
330
333
|
* from the analytics config — you never declare it twice.
|
|
331
334
|
*/
|
|
332
335
|
type SocialProofInit = {
|
|
333
|
-
/**
|
|
334
|
-
* Client kill-switch. Defaults to `true`. When `false`, the SDK skips the
|
|
335
|
-
* server check and never injects the loader, regardless of the dashboard
|
|
336
|
-
* setting.
|
|
337
|
-
*/
|
|
338
|
-
enabled?: boolean;
|
|
339
336
|
/**
|
|
340
337
|
* Origin of the saasco app hosting the social-proof widget-payload API.
|
|
341
338
|
* Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
|
|
@@ -362,7 +359,7 @@ declare class Saasco {
|
|
|
362
359
|
* @param config Configuration options.
|
|
363
360
|
* @param config.projectId The unique identifier for the project.
|
|
364
361
|
* @param config.proxy The URL of the proxy server to use, if any.
|
|
365
|
-
* @param config.autoPageTracking Whether to automatically track page views. Default is
|
|
362
|
+
* @param config.autoPageTracking Whether to automatically track page views. Default is true.
|
|
366
363
|
* @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
|
|
367
364
|
* @param config.debug Whether to log debug information. Default is false.
|
|
368
365
|
* @param config.trackUrlParams Whether to track URL parameters. Default is true.
|
|
@@ -387,20 +384,6 @@ declare class Saasco {
|
|
|
387
384
|
init(): void;
|
|
388
385
|
disableDebug(): void;
|
|
389
386
|
enableDebug(): void;
|
|
390
|
-
/**
|
|
391
|
-
* Enables and injects the support widget when it was constructed with
|
|
392
|
-
* `support: { enabled: false }`. Safe to call multiple times.
|
|
393
|
-
*/
|
|
394
|
-
enableSupport(): void;
|
|
395
|
-
/**
|
|
396
|
-
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
397
|
-
* `socialProof: { enabled: false }`, or when no `socialProof` block was
|
|
398
|
-
* passed). Injection still runs the server check, so the loader only
|
|
399
|
-
* downloads when the project has the app enabled in the dashboard.
|
|
400
|
-
* Safe to call multiple times — the loader injection is guarded against
|
|
401
|
-
* double-injection.
|
|
402
|
-
*/
|
|
403
|
-
enableSocialProof(): void;
|
|
404
387
|
/**
|
|
405
388
|
* Initialize third-party integrations
|
|
406
389
|
*/
|
|
@@ -414,7 +397,7 @@ declare class Saasco {
|
|
|
414
397
|
track(payload: TrackPayload): Promise<DoRequestResponse>;
|
|
415
398
|
/**
|
|
416
399
|
* The page method lets you record page views on your website
|
|
417
|
-
* This records the page title and path and names the event
|
|
400
|
+
* This records the page title and path and names the event using the reserved name "Page View"
|
|
418
401
|
*
|
|
419
402
|
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
420
403
|
*/
|
|
@@ -465,11 +448,8 @@ declare class Saasco {
|
|
|
465
448
|
readyCount: number;
|
|
466
449
|
};
|
|
467
450
|
/**
|
|
468
|
-
* Lazily injects the support **loader**
|
|
469
|
-
*
|
|
470
|
-
* config as `data-*` attributes. The loader (no React) injects the
|
|
471
|
-
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
472
|
-
* double-injection so re-running `init()` is a no-op.
|
|
451
|
+
* Lazily injects the support **loader** (server-gated). See
|
|
452
|
+
* {@link injectSupportLoader}. Replays identity once the script loads.
|
|
473
453
|
*/
|
|
474
454
|
private injectSupport;
|
|
475
455
|
/**
|
|
@@ -479,14 +459,13 @@ declare class Saasco {
|
|
|
479
459
|
private injectSocialProof;
|
|
480
460
|
/**
|
|
481
461
|
* Records the latest CRM identity and forwards it to the support widget.
|
|
482
|
-
* No-op when support isn't enabled.
|
|
483
462
|
*/
|
|
484
463
|
private updateSupportIdentity;
|
|
485
464
|
/**
|
|
486
465
|
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
487
466
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
488
|
-
* it (same approach as tool registration)
|
|
489
|
-
*
|
|
467
|
+
* it (same approach as tool registration). `injectSupport` calls this on
|
|
468
|
+
* script load (or immediately when the loader is already present).
|
|
490
469
|
*/
|
|
491
470
|
private pushSupportIdentity;
|
|
492
471
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -287,17 +287,22 @@ type DoRequestResponse = {
|
|
|
287
287
|
};
|
|
288
288
|
type IntegrationsConfig = (FacebookPixelIntegrationConfig | PinterestTagIntegrationConfig | TikTokPixelIntegrationConfig)[];
|
|
289
289
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
290
|
+
* Optional config for the support widget. Support is **always available
|
|
291
|
+
* wherever the analytics SDK runs** — you don't need to pass this object at
|
|
292
|
+
* all. Whether the widget actually renders is decided **server-side**: on init
|
|
293
|
+
* the SDK runs a cheap `{ enabled }` check and lazily injects the lean loader
|
|
294
|
+
* (`saasco-support-loader.js`) only when the project has the widget enabled
|
|
295
|
+
* in the dashboard, so pages where it's off never download it — and the
|
|
296
|
+
* dashboard toggle controls every install (CDN and npm) uniformly.
|
|
297
|
+
*
|
|
298
|
+
* The loader origin is resolved automatically: the CDN `<script>` origin for
|
|
299
|
+
* CDN installs, else the public Saasco CDN for npm/bundled installs. Pass this
|
|
300
|
+
* object only to override those defaults: `baseUrl`/`scriptUrl` point a
|
|
301
|
+
* same-origin, proxied, or self-hosted install at the right origin.
|
|
302
|
+
* The projectId is shared from the analytics config — you never declare it
|
|
303
|
+
* twice.
|
|
297
304
|
*/
|
|
298
305
|
type SupportInit = {
|
|
299
|
-
/** Defaults to `true` when the `support` object is provided. */
|
|
300
|
-
enabled?: boolean;
|
|
301
306
|
/** Origin of the saasco app hosting the support API. Defaults server-side to where the widget bundle is served from. */
|
|
302
307
|
baseUrl?: string;
|
|
303
308
|
/** Input placeholder for the chat composer. */
|
|
@@ -323,19 +328,11 @@ type SupportInit = {
|
|
|
323
328
|
* The loader + widget-payload origin is resolved automatically: the CDN
|
|
324
329
|
* `<script>` origin for CDN installs, else the public Saasco CDN for
|
|
325
330
|
* npm/bundled installs (which carry no script tag on the page). Pass this object
|
|
326
|
-
* only to override those defaults
|
|
327
|
-
* `data-social-proof-enabled="false"` on the CDN tag) is a client kill-switch
|
|
328
|
-
* that skips the check entirely; `baseUrl`/`scriptUrl` point a same-origin,
|
|
331
|
+
* only to override those defaults: `baseUrl`/`scriptUrl` point a same-origin,
|
|
329
332
|
* proxied, or self-hosted install at the right origin. The projectId is shared
|
|
330
333
|
* from the analytics config — you never declare it twice.
|
|
331
334
|
*/
|
|
332
335
|
type SocialProofInit = {
|
|
333
|
-
/**
|
|
334
|
-
* Client kill-switch. Defaults to `true`. When `false`, the SDK skips the
|
|
335
|
-
* server check and never injects the loader, regardless of the dashboard
|
|
336
|
-
* setting.
|
|
337
|
-
*/
|
|
338
|
-
enabled?: boolean;
|
|
339
336
|
/**
|
|
340
337
|
* Origin of the saasco app hosting the social-proof widget-payload API.
|
|
341
338
|
* Defaults to the loader bundle's origin — the CDN `<script>` origin for CDN
|
|
@@ -362,7 +359,7 @@ declare class Saasco {
|
|
|
362
359
|
* @param config Configuration options.
|
|
363
360
|
* @param config.projectId The unique identifier for the project.
|
|
364
361
|
* @param config.proxy The URL of the proxy server to use, if any.
|
|
365
|
-
* @param config.autoPageTracking Whether to automatically track page views. Default is
|
|
362
|
+
* @param config.autoPageTracking Whether to automatically track page views. Default is true.
|
|
366
363
|
* @param config.enabled Whether analytics is enabled. Default is true. Set to false for development and staging envioronments. Will still allow debug mode to be true, just no events will be sent
|
|
367
364
|
* @param config.debug Whether to log debug information. Default is false.
|
|
368
365
|
* @param config.trackUrlParams Whether to track URL parameters. Default is true.
|
|
@@ -387,20 +384,6 @@ declare class Saasco {
|
|
|
387
384
|
init(): void;
|
|
388
385
|
disableDebug(): void;
|
|
389
386
|
enableDebug(): void;
|
|
390
|
-
/**
|
|
391
|
-
* Enables and injects the support widget when it was constructed with
|
|
392
|
-
* `support: { enabled: false }`. Safe to call multiple times.
|
|
393
|
-
*/
|
|
394
|
-
enableSupport(): void;
|
|
395
|
-
/**
|
|
396
|
-
* Enables and injects the social-proof widget (e.g. after constructing with
|
|
397
|
-
* `socialProof: { enabled: false }`, or when no `socialProof` block was
|
|
398
|
-
* passed). Injection still runs the server check, so the loader only
|
|
399
|
-
* downloads when the project has the app enabled in the dashboard.
|
|
400
|
-
* Safe to call multiple times — the loader injection is guarded against
|
|
401
|
-
* double-injection.
|
|
402
|
-
*/
|
|
403
|
-
enableSocialProof(): void;
|
|
404
387
|
/**
|
|
405
388
|
* Initialize third-party integrations
|
|
406
389
|
*/
|
|
@@ -414,7 +397,7 @@ declare class Saasco {
|
|
|
414
397
|
track(payload: TrackPayload): Promise<DoRequestResponse>;
|
|
415
398
|
/**
|
|
416
399
|
* The page method lets you record page views on your website
|
|
417
|
-
* This records the page title and path and names the event
|
|
400
|
+
* This records the page title and path and names the event using the reserved name "Page View"
|
|
418
401
|
*
|
|
419
402
|
* Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
|
|
420
403
|
*/
|
|
@@ -465,11 +448,8 @@ declare class Saasco {
|
|
|
465
448
|
readyCount: number;
|
|
466
449
|
};
|
|
467
450
|
/**
|
|
468
|
-
* Lazily injects the support **loader**
|
|
469
|
-
*
|
|
470
|
-
* config as `data-*` attributes. The loader (no React) injects the
|
|
471
|
-
* cross-origin embed iframe. Deferred (`async`) and guarded against
|
|
472
|
-
* double-injection so re-running `init()` is a no-op.
|
|
451
|
+
* Lazily injects the support **loader** (server-gated). See
|
|
452
|
+
* {@link injectSupportLoader}. Replays identity once the script loads.
|
|
473
453
|
*/
|
|
474
454
|
private injectSupport;
|
|
475
455
|
/**
|
|
@@ -479,14 +459,13 @@ declare class Saasco {
|
|
|
479
459
|
private injectSocialProof;
|
|
480
460
|
/**
|
|
481
461
|
* Records the latest CRM identity and forwards it to the support widget.
|
|
482
|
-
* No-op when support isn't enabled.
|
|
483
462
|
*/
|
|
484
463
|
private updateSupportIdentity;
|
|
485
464
|
/**
|
|
486
465
|
* Pushes the current identity onto `window.SaascoSupport.identify`. The
|
|
487
466
|
* widget bundle publishes that global asynchronously, so this short-polls for
|
|
488
|
-
* it (same approach as tool registration)
|
|
489
|
-
*
|
|
467
|
+
* it (same approach as tool registration). `injectSupport` calls this on
|
|
468
|
+
* script load (or immediately when the loader is already present).
|
|
490
469
|
*/
|
|
491
470
|
private pushSupportIdentity;
|
|
492
471
|
}
|