@treasuredata/web-sdk 1.0.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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +807 -0
- package/dist/browser.d.ts +9 -0
- package/dist/checksums.txt +8 -0
- package/dist/core/config.d.ts +10 -0
- package/dist/core/config.template.d.ts +10 -0
- package/dist/core/configurator.d.ts +35 -0
- package/dist/core/sdk.d.ts +3 -0
- package/dist/index.d.ts +37 -0
- package/dist/init.d.ts +18 -0
- package/dist/loader.d.ts +59 -0
- package/dist/loader.js +1 -0
- package/dist/loader.min.js +1 -0
- package/dist/plugins/clicks.d.ts +21 -0
- package/dist/plugins/conversion-api.d.ts +23 -0
- package/dist/plugins/global-id.d.ts +17 -0
- package/dist/plugins/in-browser-message.d.ts +6 -0
- package/dist/plugins/page-personalize/bridge/constants.d.ts +9 -0
- package/dist/plugins/page-personalize/bridge/rpc.d.ts +15 -0
- package/dist/plugins/page-personalize/index.d.ts +34 -0
- package/dist/plugins/page-personalize/injection/inject.d.ts +17 -0
- package/dist/plugins/page-personalize/modes/preview.d.ts +3 -0
- package/dist/plugins/page-personalize/modes/spot-selection.d.ts +9 -0
- package/dist/plugins/page-personalize/offers.d.ts +72 -0
- package/dist/plugins/page-personalize/router.d.ts +17 -0
- package/dist/plugins/page-personalize/types.d.ts +27 -0
- package/dist/plugins/page-personalize/utils/selector-generator.d.ts +6 -0
- package/dist/plugins/personalization.d.ts +39 -0
- package/dist/plugins/record.d.ts +32 -0
- package/dist/plugins/server-cookie.d.ts +14 -0
- package/dist/plugins/session.d.ts +25 -0
- package/dist/plugins/track.d.ts +16 -0
- package/dist/plugins/utm.d.ts +16 -0
- package/dist/td-sdk.cjs +3263 -0
- package/dist/td-sdk.esm.js +3263 -0
- package/dist/td-sdk.esm.min.js +1 -0
- package/dist/td-sdk.js +3176 -0
- package/dist/td-sdk.min.cjs +1 -0
- package/dist/td-sdk.min.js +1 -0
- package/dist/treasure.d.ts +198 -0
- package/dist/types/index.d.ts +177 -0
- package/dist/utils/element.d.ts +20 -0
- package/dist/utils/lodash.d.ts +18 -0
- package/dist/utils/misc.d.ts +17 -0
- package/dist/utils/set-cookie.d.ts +14 -0
- package/dist/utils/uuid.d.ts +14 -0
- package/dist/utils/xhr.d.ts +58 -0
- package/dist/vendor/js-cookies.d.ts +19 -0
- package/package.json +90 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser/IIFE Entry Point
|
|
3
|
+
*
|
|
4
|
+
* This entry point is specifically for browser IIFE builds.
|
|
5
|
+
* It exports only Treasure as the default export so it becomes the global constructor.
|
|
6
|
+
*/
|
|
7
|
+
import Treasure from './treasure';
|
|
8
|
+
export default Treasure;
|
|
9
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
f78df7778b059bfdc572a76427956a414751e4c5bcc6aa0ef2cab5b3242b0bf7 ./loader.min.js
|
|
2
|
+
4ed5ef2e3f519aaa7cf4a612eddd67df5c18d0e6b452d5bd11b59d36f821ea3b ./td-sdk.esm.js
|
|
3
|
+
fceb3135094564669c2b760b891eea4d02165e5faab1b3078af1670f8fc04c5d ./td-sdk.esm.min.js
|
|
4
|
+
8dc322d45af0e3b2d8fc2f86245421c6111d251c368aa7f5d57555f4a487c1d7 ./td-sdk.min.js
|
|
5
|
+
80452ed288b30ea6d44f30910170679eb33ab8382ef92cce5afc0aeedc03a493 ./td-sdk.cjs
|
|
6
|
+
842c5a1495039443abf3305a7dbe1c203a3aab446b0dd52050f2dba5d5eed7a3 ./td-sdk.js
|
|
7
|
+
f78df7778b059bfdc572a76427956a414751e4c5bcc6aa0ef2cab5b3242b0bf7 ./loader.js
|
|
8
|
+
28e68c0b48b19abb08582fffad0fb5af2b69cd9f26ea8cb999bf2c60850950d2 ./td-sdk.min.cjs
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const CONFIG: {
|
|
2
|
+
readonly GLOBAL: "Treasure";
|
|
3
|
+
readonly VERSION: "1.0.0";
|
|
4
|
+
readonly HOST: "us01.records.in.treasuredata.com";
|
|
5
|
+
readonly DATABASE: "";
|
|
6
|
+
readonly PATHNAME: "/";
|
|
7
|
+
readonly FILENAME: "td-sdk";
|
|
8
|
+
readonly URL: "//cdn.treasuredata.com/sdk/web/1.0/td-sdk.min.js";
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const CONFIG: {
|
|
2
|
+
readonly GLOBAL: "@GLOBAL";
|
|
3
|
+
readonly VERSION: "@VERSION";
|
|
4
|
+
readonly HOST: "@HOST";
|
|
5
|
+
readonly DATABASE: "@DATABASE";
|
|
6
|
+
readonly PATHNAME: "@PATHNAME";
|
|
7
|
+
readonly FILENAME: "@FILENAME";
|
|
8
|
+
readonly URL: "@URL";
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=config.template.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Treasure Configurator
|
|
3
|
+
* Handles configuration validation and setup for the TD client
|
|
4
|
+
*/
|
|
5
|
+
import type { TDConfig } from '../types';
|
|
6
|
+
declare function defaultSSCCookieDomain(): string;
|
|
7
|
+
export declare const DEFAULT_CONFIG: {
|
|
8
|
+
database: "";
|
|
9
|
+
development: boolean;
|
|
10
|
+
globalIdCookie: string;
|
|
11
|
+
host: "us01.records.in.treasuredata.com";
|
|
12
|
+
logging: boolean;
|
|
13
|
+
pathname: "/";
|
|
14
|
+
requestType: string;
|
|
15
|
+
jsonpTimeout: number;
|
|
16
|
+
startInSignedMode: boolean;
|
|
17
|
+
useServerSideCookie: boolean;
|
|
18
|
+
sscDomain: typeof defaultSSCCookieDomain;
|
|
19
|
+
sscServer: (cookieDomain: string) => string;
|
|
20
|
+
storeConsentByLocalStorage: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Configure TD client configuration
|
|
24
|
+
* Pure function that takes a partial config with required `writeKey` and
|
|
25
|
+
* `database`, and returns a complete, validated config
|
|
26
|
+
*
|
|
27
|
+
* Modify DEFAULT_CONFIG to change any defaults
|
|
28
|
+
* Protocol defaults to auto-detection but can be set manually
|
|
29
|
+
* host defaults to us01.records.in.treasuredata.com
|
|
30
|
+
* pathname defaults to /
|
|
31
|
+
* requestType is always fetch
|
|
32
|
+
*/
|
|
33
|
+
export declare function configure(options: Pick<TDConfig, 'writeKey' | 'database'> & Partial<TDConfig>): TDConfig;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=configurator.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Treasure Data Web SDK - Modern TypeScript Implementation
|
|
3
|
+
*
|
|
4
|
+
* A modern, TypeScript-first analytics SDK for browser event tracking
|
|
5
|
+
* with Baseline browser support and comprehensive type safety.
|
|
6
|
+
*/
|
|
7
|
+
export { createSDK } from './core/sdk';
|
|
8
|
+
export { Treasure, default } from './treasure';
|
|
9
|
+
export { createLoader, processQueuedCalls, replaceLoaderStub } from './loader';
|
|
10
|
+
export { initSDK } from './init';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export { session, BLOCKEVENTSCOOKIE, SIGNEDMODECOOKIE } from './plugins/session';
|
|
13
|
+
export { record, _validateRecord } from './plugins/record';
|
|
14
|
+
export { track } from './plugins/track';
|
|
15
|
+
export { clicks } from './plugins/clicks';
|
|
16
|
+
export type { ClickTrackingOptions } from './plugins/clicks';
|
|
17
|
+
export { utm } from './plugins/utm';
|
|
18
|
+
export type { UTMPluginOptions } from './plugins/utm';
|
|
19
|
+
export { personalization } from './plugins/personalization';
|
|
20
|
+
export type { UserSegmentOptions, UserSegment, PersonalizationFetchConfig, } from './plugins/personalization';
|
|
21
|
+
export { pagePersonalize } from './plugins/page-personalize';
|
|
22
|
+
export type { PagePersonalizePluginAPI, ApplyPersonalizationOptions, } from './plugins/page-personalize';
|
|
23
|
+
export type { PersonalizationPayload } from './plugins/page-personalize/offers';
|
|
24
|
+
export { conversionAPI } from './plugins/conversion-api';
|
|
25
|
+
export type { ConversionAPIConfig, ConversionAPIOptions, } from './plugins/conversion-api';
|
|
26
|
+
export { serverCookie } from './plugins/server-cookie';
|
|
27
|
+
export { globalId } from './plugins/global-id';
|
|
28
|
+
export type { GlobalIdPluginAPI, GlobalIdCookieOptions, } from './plugins/global-id';
|
|
29
|
+
export { generateUUID, isValidUUID } from './utils/uuid';
|
|
30
|
+
export { setCookie, type CookieConfig } from './utils/set-cookie';
|
|
31
|
+
export { cookie } from './vendor/js-cookies';
|
|
32
|
+
export * as elementUtils from './utils/element';
|
|
33
|
+
export { adlHeaders, globalIdAdlHeaders, invariant, isLocalStorageAccessible, } from './utils/misc';
|
|
34
|
+
export { configure, DEFAULT_CONFIG } from './core/configurator';
|
|
35
|
+
export { SERVER_COOKIE_NAME } from './plugins/server-cookie';
|
|
36
|
+
export declare const version: string;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Initialization and Loader Integration
|
|
3
|
+
*
|
|
4
|
+
* This module handles the initialization of the SDK and integration with the async loader.
|
|
5
|
+
* It automatically replaces any loader stubs with actual SDK instances.
|
|
6
|
+
*/
|
|
7
|
+
import { Treasure } from './treasure';
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the SDK and replace any existing loader stubs
|
|
10
|
+
*/
|
|
11
|
+
export declare function initSDK(globalName?: string): void;
|
|
12
|
+
export { Treasure };
|
|
13
|
+
declare const _default: {
|
|
14
|
+
initSDK: typeof initSDK;
|
|
15
|
+
Treasure: typeof Treasure;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
//# sourceMappingURL=init.d.ts.map
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Treasure Data SDK Async Loader
|
|
3
|
+
*
|
|
4
|
+
* This loader creates a stub object that queues method calls before the actual SDK loads.
|
|
5
|
+
* This allows the SDK to be loaded asynchronously without blocking page rendering,
|
|
6
|
+
* while still capturing early tracking events.
|
|
7
|
+
*
|
|
8
|
+
* Usage in HTML:
|
|
9
|
+
* <script>
|
|
10
|
+
* (function(n,c){if(c[n]===void 0){c[n]=function(){c[n].clients.push(this);this._init=[Array.prototype.slice.call(arguments)]};c[n].clients=[];var action=function(method){return function(){this['_'+method]=this['_'+method]||[];this['_'+method].push(Array.prototype.slice.call(arguments));return this}};var methods=['collectTags','addRecord','blockEvents','fetchServerCookie','fetchGlobalID','fetchUserSegments','fetchPersonalization','resetUUID','ready','setSignedMode','setAnonymousMode','set','trackEvent','trackPageview','trackClicks','unblockEvents'];for(var i=0;i<methods.length;i++){var method=methods[i];c[n].prototype[method]=action(method)}var s=document.createElement('script');s.type='text/javascript';s.async=!0;s.src=(document.location.protocol==='https:'?'https:':'http:')+'/path/to/td.js';var t=document.getElementsByTagName('script')[0];t.parentNode.insertBefore(s,t)}}('td',this));
|
|
11
|
+
*
|
|
12
|
+
* // Now you can use td immediately
|
|
13
|
+
* var client = new td({writeKey: 'key', database: 'db'});
|
|
14
|
+
* client.trackEvent('table', {event: 'data'});
|
|
15
|
+
* </script>
|
|
16
|
+
*/
|
|
17
|
+
interface LoaderClient {
|
|
18
|
+
_init?: any[][];
|
|
19
|
+
_collectTags?: any[][];
|
|
20
|
+
_addRecord?: any[][];
|
|
21
|
+
_blockEvents?: any[][];
|
|
22
|
+
_fetchServerCookie?: any[][];
|
|
23
|
+
_fetchGlobalID?: any[][];
|
|
24
|
+
_fetchUserSegments?: any[][];
|
|
25
|
+
_fetchPersonalization?: any[][];
|
|
26
|
+
_resetUUID?: any[][];
|
|
27
|
+
_ready?: any[][];
|
|
28
|
+
_setSignedMode?: any[][];
|
|
29
|
+
_setAnonymousMode?: any[][];
|
|
30
|
+
_set?: any[][];
|
|
31
|
+
_trackEvent?: any[][];
|
|
32
|
+
_trackPageview?: any[][];
|
|
33
|
+
_trackClicks?: any[][];
|
|
34
|
+
_unblockEvents?: any[][];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* List of SDK methods that should be stubbed in the loader
|
|
38
|
+
* Order matters for consistency between loader and processor
|
|
39
|
+
*/
|
|
40
|
+
export declare const LOADER_METHODS: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Creates the async loader stub function
|
|
43
|
+
*/
|
|
44
|
+
export declare function createLoader(globalName: string, scriptUrl: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Processes queued calls from the loader stub
|
|
47
|
+
*/
|
|
48
|
+
export declare function processQueuedCalls(loaderClient: LoaderClient, actualClient: any): void;
|
|
49
|
+
/**
|
|
50
|
+
* Replaces the loader stub with the actual SDK
|
|
51
|
+
*/
|
|
52
|
+
export declare function replaceLoaderStub(globalName: string, sdkConstructor: any): void;
|
|
53
|
+
declare const _default: {
|
|
54
|
+
createLoader: typeof createLoader;
|
|
55
|
+
processQueuedCalls: typeof processQueuedCalls;
|
|
56
|
+
replaceLoaderStub: typeof replaceLoaderStub;
|
|
57
|
+
};
|
|
58
|
+
export default _default;
|
|
59
|
+
//# sourceMappingURL=loader.d.ts.map
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["set","collectTags","blockEvents","unblockEvents","setSignedMode","setAnonymousMode","fetchServerCookie","fetchGlobalID","fetchUserSegments","fetchPersonalization","resetUUID","addRecord","trackEvent","trackPageview","trackClicks","ready"],c=0;c<s.length;c++){var o=s[c];e[t].prototype[o]=r(o)}var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/web/1.0/td-sdk.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(n,i)}}("Treasure",this);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["set","collectTags","blockEvents","unblockEvents","setSignedMode","setAnonymousMode","fetchServerCookie","fetchGlobalID","fetchUserSegments","fetchPersonalization","resetUUID","addRecord","trackEvent","trackPageview","trackClicks","ready"],c=0;c<s.length;c++){var o=s[c];e[t].prototype[o]=r(o)}var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/web/1.0/td-sdk.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(n,i)}}("Treasure",this);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clicks Plugin
|
|
3
|
+
* Automatically tracks clicks on interactive elements
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasurePlugin } from '../types';
|
|
6
|
+
export interface ClickTrackingOptions {
|
|
7
|
+
/** Element to observe (default: document) */
|
|
8
|
+
element?: EventTarget;
|
|
9
|
+
/** Function to extend click data */
|
|
10
|
+
extendClickData?: (event: Event, data: Record<string, string>) => Record<string, string> | null;
|
|
11
|
+
/** Attribute name to ignore elements (default: 'td-ignore') */
|
|
12
|
+
ignoreAttribute?: string;
|
|
13
|
+
/** Table name for click events (default: 'clicks') */
|
|
14
|
+
tableName?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ClicksPluginAPI {
|
|
17
|
+
/** Track clicks with optional configuration */
|
|
18
|
+
trackClicks: (options?: ClickTrackingOptions) => (() => void) | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function clicks(): TreasurePlugin<ClicksPluginAPI>;
|
|
21
|
+
//# sourceMappingURL=clicks.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion API Support Plugin
|
|
3
|
+
* Collects advertising cookies and parameters from various platforms for conversion tracking
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasurePlugin } from '../types';
|
|
6
|
+
export interface ConversionAPIConfig {
|
|
7
|
+
/** Vendors to collect tags from */
|
|
8
|
+
vendors?: string[];
|
|
9
|
+
/** Cookie names to collect */
|
|
10
|
+
cookies?: string[];
|
|
11
|
+
/** URL parameter names to collect */
|
|
12
|
+
params?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface ConversionAPIOptions {
|
|
15
|
+
/** Custom Google Conversion Linker prefix (default: '_gcl') */
|
|
16
|
+
gclPrefix?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ConversionAPIPluginAPI {
|
|
19
|
+
/** Collect conversion tracking tags */
|
|
20
|
+
collectTags(config?: ConversionAPIConfig, options?: ConversionAPIOptions): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function conversionAPI(): TreasurePlugin<ConversionAPIPluginAPI>;
|
|
23
|
+
//# sourceMappingURL=conversion-api.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global ID Plugin
|
|
3
|
+
* Fetches and caches the Treasure Data Global ID.
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasurePlugin } from '../types';
|
|
6
|
+
export interface GlobalIdCookieOptions {
|
|
7
|
+
path?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
maxAge?: number | string | Date;
|
|
11
|
+
sameSite?: 'None' | 'Lax' | 'Strict';
|
|
12
|
+
}
|
|
13
|
+
export interface GlobalIdPluginAPI {
|
|
14
|
+
fetchGlobalID(success?: (globalId: string | null) => void, error?: (error: unknown) => void, forceFetch?: boolean, options?: GlobalIdCookieOptions): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function globalId(): TreasurePlugin<GlobalIdPluginAPI>;
|
|
17
|
+
//# sourceMappingURL=global-id.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-browser message rendering for personalization API responses
|
|
3
|
+
* Handles popup (Shadow DOM modal) and inline (DOM replacement) message types
|
|
4
|
+
*/
|
|
5
|
+
export declare function handlePersonalizationResponse(response: unknown): void;
|
|
6
|
+
//# sourceMappingURL=in-browser-message.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** URL query parameter that selects the active mode. */
|
|
2
|
+
export declare const MODE_QUERY_PARAM = "td-personalization-mode";
|
|
3
|
+
/** Init message data value. */
|
|
4
|
+
export declare const INIT_MESSAGE_TYPE = "td:p13n-studio:init";
|
|
5
|
+
/** Ready message data value. */
|
|
6
|
+
export declare const READY_MESSAGE_TYPE = "td:p13n-studio:ready";
|
|
7
|
+
/** Trusted parent origins for cross-frame communication. */
|
|
8
|
+
export declare const ALLOWED_PARENT_ORIGINS: readonly string[];
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Remote } from 'comlink';
|
|
2
|
+
import type { ModeRuntime } from '../router';
|
|
3
|
+
/**
|
|
4
|
+
* Exposes an RPC object to the parent frame over the handshake port.
|
|
5
|
+
*/
|
|
6
|
+
export declare function exposeRpc<T extends object>(rpc: T): ModeRuntime;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps the parent frame's RPC over the handshake port. `getApi()` returns
|
|
9
|
+
* `null` until the handshake completes, then the live `Remote<T>`. After
|
|
10
|
+
* `dispose()`, returns `null` again.
|
|
11
|
+
*/
|
|
12
|
+
export declare function wrapParentRpc<T extends object>(): ModeRuntime & {
|
|
13
|
+
getApi: () => Remote<T> | null;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Treasure Data Personalization Studio runtime plugin.
|
|
3
|
+
*
|
|
4
|
+
* Customer-facing. Exposes the page-personalization surface
|
|
5
|
+
* (`personalizePage`, `applyPersonalization`) for fetching and applying
|
|
6
|
+
* personalized content to the page.
|
|
7
|
+
*
|
|
8
|
+
* It also hosts the internal Studio `preview` integration, which customers do
|
|
9
|
+
* not interact with directly.
|
|
10
|
+
*/
|
|
11
|
+
import type { JSONValue, TreasurePlugin } from '../../types';
|
|
12
|
+
import type { PersonalizationFetchConfig } from '../personalization';
|
|
13
|
+
import { type PersonalizationPayload } from './offers';
|
|
14
|
+
/** Options for {@link PagePersonalizePluginAPI.applyPersonalization}. */
|
|
15
|
+
export interface ApplyPersonalizationOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Apply even while the page is embedded in Personalization Studio.
|
|
18
|
+
* Defaults to false to avoid clobbering spot previews/picker.
|
|
19
|
+
*/
|
|
20
|
+
force?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface PagePersonalizePluginAPI {
|
|
23
|
+
/**
|
|
24
|
+
* Apply a previously fetched personalization payload to the current page.
|
|
25
|
+
*/
|
|
26
|
+
applyPersonalization(payload: PersonalizationPayload, options?: ApplyPersonalizationOptions): void;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch personalization offers and apply them to the current page.
|
|
29
|
+
* The success callback receives the fetched payload.
|
|
30
|
+
*/
|
|
31
|
+
personalizePage(config: PersonalizationFetchConfig, data?: Record<string, JSONValue> | null, successCallback?: (payload: PersonalizationPayload) => void, errorCallback?: (error: Error) => void): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function pagePersonalize(): TreasurePlugin<PagePersonalizePluginAPI>;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared shadow-DOM spot injection. Per-spot primitives; callers iterate
|
|
3
|
+
* and validate inputs.
|
|
4
|
+
*
|
|
5
|
+
* `applySpot` never throws — platform exceptions are caught and converted
|
|
6
|
+
* into structured `ApplySpotResult` failures.
|
|
7
|
+
*/
|
|
8
|
+
import type { ApplySpotResult, Spot, SpotRef } from '../types';
|
|
9
|
+
/** Inject one spot into `doc`. Caller MUST pass a structurally-valid `Spot`. */
|
|
10
|
+
export declare function applySpot(doc: Document, spot: Spot): ApplySpotResult;
|
|
11
|
+
/**
|
|
12
|
+
* Restore visibility of original light DOM under the spot's host. Inserts a
|
|
13
|
+
* `<slot>` because the platform offers no way to detach a shadow root once
|
|
14
|
+
* attached. Caller MUST pass a structurally-valid `SpotRef`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function removeSpot(doc: Document, ref: SpotRef): void;
|
|
17
|
+
//# sourceMappingURL=inject.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spot-selection mode handler.
|
|
3
|
+
*
|
|
4
|
+
* Highlights DOM elements on hover and sends a stable CSS selector to the
|
|
5
|
+
* parent Studio via Comlink on click.
|
|
6
|
+
*/
|
|
7
|
+
import type { ModeHandler } from '../router';
|
|
8
|
+
export declare const spotSelectionHandler: ModeHandler;
|
|
9
|
+
//# sourceMappingURL=spot-selection.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personalization-offer decoding for the page-personalize "apply" path.
|
|
3
|
+
*
|
|
4
|
+
* The p13n API returns a map of named offers. Every value inside an offer's
|
|
5
|
+
* `attributes` arrives as a JSON string (TD convention), so each field is
|
|
6
|
+
* parsed before use. Of all offers, exactly one wins: the latest in-window
|
|
7
|
+
* campaign, with audience rank as the tie-breaker (see `selectWinningOffer`).
|
|
8
|
+
* Its `content` entries become `Spot`s for shadow-DOM injection.
|
|
9
|
+
*/
|
|
10
|
+
import type { Spot } from './types';
|
|
11
|
+
/** One personalization entry as authored in Studio, parsed from untrusted p13n
|
|
12
|
+
* JSON and validated at runtime. */
|
|
13
|
+
export interface P13nEntry {
|
|
14
|
+
/** CSS selector for the host element. */
|
|
15
|
+
css_selector: string;
|
|
16
|
+
/** HTML injected into the host's shadow root. */
|
|
17
|
+
html_value: string;
|
|
18
|
+
/** CSS injected into the host's shadow root. */
|
|
19
|
+
css_value: string;
|
|
20
|
+
/** Creative/personalization identifier for impression reporting. */
|
|
21
|
+
id: number;
|
|
22
|
+
}
|
|
23
|
+
/** Offer attributes. Every value is delivered as a string by the p13n API. Keys
|
|
24
|
+
* are prefixed with `td_personalization.` per the API return contract. */
|
|
25
|
+
export interface PersonalizationOfferAttributes {
|
|
26
|
+
/** JSON string encoding a `P13nEntry[]`. */
|
|
27
|
+
'td_personalization.content'?: string;
|
|
28
|
+
/** Numeric string; lower value = higher rank. Tie-breaker among offers that
|
|
29
|
+
* share the latest `campaign_updated_at`. */
|
|
30
|
+
'td_personalization.audience_rank'?: string;
|
|
31
|
+
/** Unix-seconds string; primary selection key (latest wins). */
|
|
32
|
+
'td_personalization.campaign_updated_at'?: string;
|
|
33
|
+
/** Unix-seconds string; campaign becomes active at this time (inclusive). */
|
|
34
|
+
'td_personalization.campaigns_start_date'?: string;
|
|
35
|
+
/** Unix-seconds string; campaign stops being active at this time (exclusive). */
|
|
36
|
+
'td_personalization.campaigns_end_date'?: string;
|
|
37
|
+
/** Campaign identifier shared by the offer's content entries. */
|
|
38
|
+
'td_personalization.campaign'?: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface PersonalizationOffer {
|
|
42
|
+
attributes?: PersonalizationOfferAttributes | null;
|
|
43
|
+
}
|
|
44
|
+
export interface PersonalizationPayload {
|
|
45
|
+
offers?: Record<string, PersonalizationOffer> | null;
|
|
46
|
+
}
|
|
47
|
+
export interface ImpressionRef {
|
|
48
|
+
campaign: string;
|
|
49
|
+
creative: string;
|
|
50
|
+
}
|
|
51
|
+
export interface DecodedSpot {
|
|
52
|
+
spot: Spot;
|
|
53
|
+
/** Null when the entry can't be attributed; the spot is still injected. */
|
|
54
|
+
impression: ImpressionRef | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Pick the single latest in-window offer, tie-broken by audience rank.
|
|
58
|
+
*
|
|
59
|
+
* Selection order over `payload.offers` (insertion order preserved):
|
|
60
|
+
* 1. Drop offers outside their active campaign window.
|
|
61
|
+
* 2. Drop offers without a finite numeric `audience_rank`.
|
|
62
|
+
* 3. Winner = highest `campaign_updated_at` (missing treated as `-Infinity`);
|
|
63
|
+
* ties broken by lowest `audience_rank`, then by first encountered.
|
|
64
|
+
*
|
|
65
|
+
* Returns `null` when no offer qualifies. `now` defaults to the current time in
|
|
66
|
+
* unix seconds and is injectable for deterministic tests.
|
|
67
|
+
*/
|
|
68
|
+
export declare function selectWinningOffer(payload: PersonalizationPayload | null | undefined, now?: number): PersonalizationOffer | null;
|
|
69
|
+
/** Decode the single winning offer's entries into spots; malformed entries are
|
|
70
|
+
* dropped, so the result may be shorter than the offer's content. */
|
|
71
|
+
export declare function decodeOffers(payload: PersonalizationPayload | null | undefined, now?: number): DecodedSpot[];
|
|
72
|
+
//# sourceMappingURL=offers.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mode detection + dispatch for pagePersonalize. Adding a mode: drop a
|
|
3
|
+
* handler in `modes/` and register it in `MODE_HANDLERS`.
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasureCore } from '../../types';
|
|
6
|
+
import type { PagePersonalizeMode } from './types';
|
|
7
|
+
export interface ModeHandler {
|
|
8
|
+
readonly mode: PagePersonalizeMode;
|
|
9
|
+
/** Returning `null` is a clean refusal; the router treats it as a no-op. */
|
|
10
|
+
activate(core: TreasureCore): ModeRuntime | null;
|
|
11
|
+
}
|
|
12
|
+
export interface ModeRuntime {
|
|
13
|
+
/** Reserved for future SPA route-change teardown. */
|
|
14
|
+
dispose?(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function runRouter(core: TreasureCore): PagePersonalizeMode | null;
|
|
17
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Internal types for the pagePersonalize plugin. */
|
|
2
|
+
export interface Spot {
|
|
3
|
+
selector: string;
|
|
4
|
+
html?: string;
|
|
5
|
+
css?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ApplySpotResult {
|
|
8
|
+
/**
|
|
9
|
+
* Echoes back the caller's `selector` for resolved paths (always a string)
|
|
10
|
+
* and roundtrips the original faulty value verbatim for `invalid_spot`,
|
|
11
|
+
* so Studio can attribute per-row failures.
|
|
12
|
+
*/
|
|
13
|
+
selector: unknown;
|
|
14
|
+
success: boolean;
|
|
15
|
+
reason?: 'invalid_spot' | 'not_found' | 'unsupported_element' | 'already_has_shadow' | 'injection_error';
|
|
16
|
+
matchCount?: number;
|
|
17
|
+
}
|
|
18
|
+
export type PagePersonalizeMode = 'preview' | 'spot-selection';
|
|
19
|
+
export type SpotRef = Pick<Spot, 'selector'>;
|
|
20
|
+
export interface PreviewRpc {
|
|
21
|
+
applySpots(spots: Spot[]): Promise<ApplySpotResult[]>;
|
|
22
|
+
removeSpots(spots: SpotRef[]): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface SpotSelectionParentRpc {
|
|
25
|
+
onSpotSelected(selector: string): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personalization Plugin
|
|
3
|
+
* Provides user segmentation and personalization capabilities
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasurePlugin, JSONValue } from '../types';
|
|
6
|
+
export interface UserSegmentOptions {
|
|
7
|
+
/** Audience token(s) for the userId */
|
|
8
|
+
audienceToken: string | string[];
|
|
9
|
+
/** Key-value pairs to be sent for this segment */
|
|
10
|
+
keys?: Record<string, JSONValue>;
|
|
11
|
+
}
|
|
12
|
+
export interface UserSegment {
|
|
13
|
+
/** Segment key data */
|
|
14
|
+
key: Record<string, JSONValue>;
|
|
15
|
+
/** Segment values */
|
|
16
|
+
values: string[];
|
|
17
|
+
/** Segment attributes */
|
|
18
|
+
attributes: Record<string, JSONValue>;
|
|
19
|
+
}
|
|
20
|
+
export interface PersonalizationFetchConfig {
|
|
21
|
+
/** Personalization endpoint */
|
|
22
|
+
endpoint: string;
|
|
23
|
+
/** Database name */
|
|
24
|
+
database: string;
|
|
25
|
+
/** Table name */
|
|
26
|
+
table: string;
|
|
27
|
+
/** Personalization token */
|
|
28
|
+
token: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PersonalizationPluginAPI {
|
|
31
|
+
/** Fetch user segments */
|
|
32
|
+
fetchUserSegments(options: UserSegmentOptions, successCallback?: (segments: UserSegment[]) => void, errorCallback?: (error: Error) => void): void;
|
|
33
|
+
/** Fetch user segments (overload for token-only usage) */
|
|
34
|
+
fetchUserSegments(audienceToken: string | string[], successCallback?: (segments: UserSegment[]) => void, errorCallback?: (error: Error) => void): void;
|
|
35
|
+
/** Fetch personalization data */
|
|
36
|
+
fetchPersonalization(config: PersonalizationFetchConfig, data?: Record<string, JSONValue> | null, successCallback?: (response: Record<string, JSONValue>) => void, errorCallback?: (error: Error) => void): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function personalization(): TreasurePlugin<PersonalizationPluginAPI>;
|
|
39
|
+
//# sourceMappingURL=personalization.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Record Plugin
|
|
3
|
+
* Core functionality for tracking events and managing storage
|
|
4
|
+
* Converted from core/record.ts to plugin architecture
|
|
5
|
+
*/
|
|
6
|
+
import type { TreasurePlugin, JSONValue, TrackResponse, TDError } from '../types';
|
|
7
|
+
export interface AddRecordOptions {
|
|
8
|
+
/** Defaults to the SDK's configured database when omitted. */
|
|
9
|
+
database?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RecordPluginAPI {
|
|
12
|
+
addRecord(table: string, record: Record<string, JSONValue>, success?: (response: TrackResponse) => void, error?: (error: TDError) => void, options?: AddRecordOptions): void;
|
|
13
|
+
}
|
|
14
|
+
export interface SubmitRecordRequest {
|
|
15
|
+
apikey: string;
|
|
16
|
+
record: Record<string, JSONValue>;
|
|
17
|
+
time: number | null;
|
|
18
|
+
url: string;
|
|
19
|
+
inSignedMode: boolean;
|
|
20
|
+
isGlobalIdEnabled: boolean;
|
|
21
|
+
windowBeingUnloaded: boolean;
|
|
22
|
+
timeoutMs: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate record data
|
|
26
|
+
*/
|
|
27
|
+
declare function validateRecord(table: string, record: Record<string, JSONValue>): void;
|
|
28
|
+
export declare const _validateRecord: typeof validateRecord;
|
|
29
|
+
export declare function record(): TreasurePlugin<RecordPluginAPI>;
|
|
30
|
+
export declare function submitRecord(request: SubmitRecordRequest, success?: (response: TrackResponse) => void, error?: (error: TDError) => void): Promise<void>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side Cookie Plugin
|
|
3
|
+
*
|
|
4
|
+
* This functionality complies with ITP 1.2 tracking.
|
|
5
|
+
* Contact customer support for enabling this feature.
|
|
6
|
+
*/
|
|
7
|
+
import type { TreasurePlugin } from '../types';
|
|
8
|
+
export interface ServerCookiePluginAPI {
|
|
9
|
+
/** Fetch server-side cookie ID */
|
|
10
|
+
fetchServerCookie(success?: (serverSideId: string) => void, error?: (error: string | Error) => void, forceFetch?: boolean): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const SERVER_COOKIE_NAME = "_td_ssc_id";
|
|
13
|
+
export declare function serverCookie(): TreasurePlugin<ServerCookiePluginAPI>;
|
|
14
|
+
//# sourceMappingURL=server-cookie.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Plugin
|
|
3
|
+
* Owns identity (UUID) and consent (signed/anonymous mode) state.
|
|
4
|
+
* Both record and track read from this plugin via sdk.
|
|
5
|
+
*/
|
|
6
|
+
import type { TreasurePlugin, StorageConfiguration, JSONValue } from '../types';
|
|
7
|
+
export declare const BLOCKEVENTSCOOKIE = "__td_blockEvents";
|
|
8
|
+
export declare const SIGNEDMODECOOKIE = "__td_signed";
|
|
9
|
+
export interface SessionPluginAPI {
|
|
10
|
+
inSignedMode(): boolean;
|
|
11
|
+
setSignedMode(): void;
|
|
12
|
+
setAnonymousMode(keepIdentifier?: boolean): void;
|
|
13
|
+
blockEvents(): void;
|
|
14
|
+
unblockEvents(): void;
|
|
15
|
+
areEventsBlocked(): boolean;
|
|
16
|
+
getUUID(): string;
|
|
17
|
+
resetUUID(suggestedStorage?: StorageConfiguration, suggestedClientId?: string): void;
|
|
18
|
+
set(table: string | Record<string, JSONValue>, property?: string | Record<string, JSONValue>, value?: JSONValue): void;
|
|
19
|
+
get(table?: string, key?: string): JSONValue;
|
|
20
|
+
removeCachedGlobalID(): void;
|
|
21
|
+
removeServerCookie(): void;
|
|
22
|
+
isGlobalIdEnabled(): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function session(): TreasurePlugin<SessionPluginAPI>;
|
|
25
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Track Plugin
|
|
3
|
+
* Provides event tracking with UUID management and global values
|
|
4
|
+
*/
|
|
5
|
+
import type { TreasurePlugin, JSONValue, TrackResponse, TDError, PersonalizationOptions } from '../types';
|
|
6
|
+
export interface TrackPluginAPI {
|
|
7
|
+
trackEvent(table?: string, record?: Record<string, JSONValue>, success?: (result: TrackResponse) => void, failure?: (error: TDError) => void): void;
|
|
8
|
+
trackPageview(table?: string, success?: (result: TrackResponse) => void, failure?: (error: TDError) => void, options?: {
|
|
9
|
+
payload?: Record<string, JSONValue>;
|
|
10
|
+
}): void;
|
|
11
|
+
getTrackValues(): Record<string, JSONValue>;
|
|
12
|
+
getPersonalizationConfig(): PersonalizationOptions | undefined;
|
|
13
|
+
setPersonalizationConfig(options?: PersonalizationOptions): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function track(): TreasurePlugin<TrackPluginAPI>;
|
|
16
|
+
//# sourceMappingURL=track.d.ts.map
|