flowgrid-sdk 1.6.10 → 1.7.1
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/dist/browser.d.ts +9 -1
- package/dist/browser.js +91 -2
- package/dist/browser.js.map +1 -1
- package/dist/flowgrid.min.js +1 -1
- package/dist/flowgrid.min.js.map +1 -1
- package/dist/lib/features/core/declarativeExperiments.d.ts +57 -0
- package/dist/lib/features/core/declarativeExperiments.js +198 -0
- package/dist/lib/features/core/declarativeExperiments.js.map +1 -0
- package/dist/lib/features/core/experiment.d.ts +71 -0
- package/dist/lib/features/core/experiment.js +164 -2
- package/dist/lib/features/core/experiment.js.map +1 -1
- package/dist/lib/flowgrid.d.ts +7 -2
- package/dist/lib/flowgrid.js +3 -3
- package/dist/lib/flowgrid.js.map +1 -1
- package/dist/lib/tracking/core/experiment.d.ts +12 -0
- package/dist/lib/tracking/core/experiment.js +14 -0
- package/dist/lib/tracking/core/experiment.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```html
|
|
12
|
-
* <script src="https://cdn.
|
|
12
|
+
* <script src="https://cdn.flow-grid.xyz/flowgrid.min.js"></script>
|
|
13
13
|
* <script>
|
|
14
14
|
* FlowGrid.init({ webId: 'your-web-id', apiKey: 'your-api-key' });
|
|
15
15
|
* FlowGrid.track('button_click', { button: 'signup' });
|
|
@@ -46,6 +46,7 @@ type BrowserFacade = {
|
|
|
46
46
|
identify: FlowGrid["identifyUser"];
|
|
47
47
|
defineFeature: FlowGrid["defineFeature"];
|
|
48
48
|
experiment: FlowGrid["experiment"];
|
|
49
|
+
wireExperiments(): void;
|
|
49
50
|
productView(product: BrowserProduct, properties?: Record<string, unknown>): ReturnType<FlowGrid["products"]["view"]>;
|
|
50
51
|
addToCart(product: BrowserProduct, quantity?: number, cartId?: string): ReturnType<FlowGrid["cart"]["add"]>;
|
|
51
52
|
purchase(order: BrowserOrder): ReturnType<FlowGrid["purchases"]["complete"]>;
|
|
@@ -55,6 +56,13 @@ declare global {
|
|
|
55
56
|
interface Window {
|
|
56
57
|
FlowGrid: BrowserFacade;
|
|
57
58
|
flowgrid: BrowserFacade;
|
|
59
|
+
/**
|
|
60
|
+
* Optional full config for the no-build auto-init path. Set this *before*
|
|
61
|
+
* the `<script>` tag to enable replay, autoTrack tuning, user identify,
|
|
62
|
+
* consent, custom endpoint/transport, etc. without writing an `init()` call.
|
|
63
|
+
* `webId` may be omitted here and supplied via `data-site` instead.
|
|
64
|
+
*/
|
|
65
|
+
FlowGridConfig?: Partial<FlowGridInitConfig>;
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
export { FlowGrid };
|
package/dist/browser.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```html
|
|
13
|
-
* <script src="https://cdn.
|
|
13
|
+
* <script src="https://cdn.flow-grid.xyz/flowgrid.min.js"></script>
|
|
14
14
|
* <script>
|
|
15
15
|
* FlowGrid.init({ webId: 'your-web-id', apiKey: 'your-api-key' });
|
|
16
16
|
* FlowGrid.track('button_click', { button: 'signup' });
|
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.FlowGrid = void 0;
|
|
24
24
|
const flowgrid_1 = require("./lib/flowgrid");
|
|
25
25
|
Object.defineProperty(exports, "FlowGrid", { enumerable: true, get: function () { return flowgrid_1.FlowGrid; } });
|
|
26
|
+
const declarativeExperiments_1 = require("./lib/features/core/declarativeExperiments");
|
|
26
27
|
function getInstance() {
|
|
27
28
|
const instance = flowgrid_1.FlowGrid.instance();
|
|
28
29
|
if (!instance) {
|
|
@@ -90,6 +91,13 @@ const browserFlowGrid = {
|
|
|
90
91
|
experiment(experimentId, options) {
|
|
91
92
|
return getInstance().experiment(experimentId, options);
|
|
92
93
|
},
|
|
94
|
+
// Manually (re-)scan the DOM for `data-fg-*` experiment attributes. The
|
|
95
|
+
// no-build path wires this automatically; SPA/programmatic users call it
|
|
96
|
+
// after a client-side navigation re-renders the page.
|
|
97
|
+
wireExperiments() {
|
|
98
|
+
const wiring = (0, declarativeExperiments_1.wireDeclarativeExperiments)(getInstance());
|
|
99
|
+
wiring.flushLoad();
|
|
100
|
+
},
|
|
93
101
|
productView(product, properties) {
|
|
94
102
|
return getInstance().products.view(normalizeProduct(product), properties);
|
|
95
103
|
},
|
|
@@ -100,9 +108,90 @@ const browserFlowGrid = {
|
|
|
100
108
|
return getInstance().purchases.complete(normalizeOrder(order));
|
|
101
109
|
},
|
|
102
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Read init config from the loading `<script>` tag's data attributes, so a
|
|
113
|
+
* no-build install can self-initialize:
|
|
114
|
+
*
|
|
115
|
+
* ```html
|
|
116
|
+
* <script src="https://cdn.flow-grid.xyz/flowgrid.min.js" data-site="YOUR_WEBSITE_ID"></script>
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* Config sources, lowest → highest precedence:
|
|
120
|
+
* 1. `window.FlowGridConfig` — a full {@link FlowGridInitConfig} object set
|
|
121
|
+
* *before* the tag loads. This is how the no-build path enables replay,
|
|
122
|
+
* autoTrack tuning, user identify, consent, custom transport, etc. — every
|
|
123
|
+
* option, declaratively, with no imperative `init()` call.
|
|
124
|
+
* 2. `data-*` attributes on the tag (`data-site`/`data-website-id`/`data-web-id`,
|
|
125
|
+
* `data-api-key`, `data-endpoint`, `data-replay`).
|
|
126
|
+
*
|
|
127
|
+
* `data-manual` suppresses auto-init entirely (call `FlowGrid.init()` yourself).
|
|
128
|
+
* `apiKey` is optional (web_id-only mode) but recommended. Returns `null` when
|
|
129
|
+
* there's no resolvable web id or auto-init is suppressed, leaving the manual
|
|
130
|
+
* `FlowGrid.init({...})` path fully in control.
|
|
131
|
+
*/
|
|
132
|
+
function readAutoInitConfig() {
|
|
133
|
+
const el = typeof document !== "undefined"
|
|
134
|
+
? document.currentScript
|
|
135
|
+
: null;
|
|
136
|
+
const attr = (name) => el && typeof el.getAttribute === "function" ? el.getAttribute(name) : null;
|
|
137
|
+
// Programmatic users opt out of auto-init and configure everything in code.
|
|
138
|
+
if (attr("data-manual") != null)
|
|
139
|
+
return null;
|
|
140
|
+
const fromGlobal = typeof window !== "undefined" ? window.FlowGridConfig : undefined;
|
|
141
|
+
const webId = attr("data-site") ||
|
|
142
|
+
attr("data-website-id") ||
|
|
143
|
+
attr("data-web-id") ||
|
|
144
|
+
fromGlobal?.webId;
|
|
145
|
+
if (!webId)
|
|
146
|
+
return null;
|
|
147
|
+
// Spread the global config first so its replay/autoTrack/user/consent/transport
|
|
148
|
+
// survive; data-* attributes (and the resolved webId) win where present.
|
|
149
|
+
const config = {
|
|
150
|
+
...fromGlobal,
|
|
151
|
+
webId,
|
|
152
|
+
apiKey: attr("data-api-key") ?? fromGlobal?.apiKey,
|
|
153
|
+
endpoint: attr("data-endpoint") ?? fromGlobal?.endpoint,
|
|
154
|
+
};
|
|
155
|
+
// Simple on/off replay via attribute (the options-object form goes through
|
|
156
|
+
// FlowGridConfig). Don't override an explicit FlowGridConfig.replay.
|
|
157
|
+
const replayAttr = attr("data-replay");
|
|
158
|
+
if (replayAttr != null && config.replay === undefined) {
|
|
159
|
+
config.replay = replayAttr !== "false";
|
|
160
|
+
}
|
|
161
|
+
return { config, runExperiments: attr("data-no-experiments") == null };
|
|
162
|
+
}
|
|
103
163
|
if (typeof window !== "undefined") {
|
|
164
|
+
// `FlowGrid` is always the SDK facade. `flowgrid` (lowercase) may already be
|
|
165
|
+
// claimed by the core flowgrid.js snippet (a different API) — don't clobber it.
|
|
104
166
|
window.FlowGrid = browserFlowGrid;
|
|
105
|
-
window.flowgrid
|
|
167
|
+
if (typeof window.flowgrid === "undefined") {
|
|
168
|
+
window.flowgrid = browserFlowGrid;
|
|
169
|
+
}
|
|
170
|
+
// Auto-init from FlowGridConfig / data-* (no-build path). Skipped entirely if
|
|
171
|
+
// an instance already exists (a synchronous manual init won) or `data-manual`
|
|
172
|
+
// is set — so full programmatic configuration is never locked out.
|
|
173
|
+
const auto = readAutoInitConfig();
|
|
174
|
+
if (auto && !flowgrid_1.FlowGrid.instance()) {
|
|
175
|
+
try {
|
|
176
|
+
const fg = flowgrid_1.FlowGrid.init(auto.config);
|
|
177
|
+
// Zero-config experiments: assign + apply the site's dashboard-configured
|
|
178
|
+
// tests with no author JS. Opt out with `data-no-experiments` on the tag.
|
|
179
|
+
if (auto.runExperiments) {
|
|
180
|
+
// Wire the declarative `data-fg-*` attribute layer now (click/submit/view
|
|
181
|
+
// listeners + a MutationObserver for dynamically-injected DOM), then flush
|
|
182
|
+
// any page-level `load` goals once assignment settles — so a marketer needs
|
|
183
|
+
// only HTML attributes to record conversions, never JavaScript.
|
|
184
|
+
const wiring = (0, declarativeExperiments_1.wireDeclarativeExperiments)(fg);
|
|
185
|
+
fg.experiments
|
|
186
|
+
.initFromServer()
|
|
187
|
+
.catch(() => { })
|
|
188
|
+
.then(() => wiring.flushLoad());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
/* init surfaces its own error; never throw from the bundle's top level */
|
|
193
|
+
}
|
|
194
|
+
}
|
|
106
195
|
}
|
|
107
196
|
exports.default = browserFlowGrid;
|
|
108
197
|
//# sourceMappingURL=browser.js.map
|
package/dist/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,6CAA8D;
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,6CAA8D;AAwPrD,yFAxPA,mBAAQ,O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