@builder.io/sdk-svelte 0.0.5 → 0.0.6
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/package/--package.json +1 -1
- package/package/components/render-content/render-content.svelte +13 -7
- package/package/functions/track.d.ts +35 -5
- package/package/functions/track.js +5 -4
- package/package/index.d.ts +1 -0
- package/package/index.js +1 -0
- package/package.json +1 -1
- package/src/components/render-content/render-content.svelte +13 -7
- package/src/functions/track.ts +45 -11
- package/src/index.ts +1 -0
package/package/--package.json
CHANGED
|
@@ -11,7 +11,7 @@ import { isBrowser } from "../../functions/is-browser.js";
|
|
|
11
11
|
import { isEditing } from "../../functions/is-editing.js";
|
|
12
12
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
13
13
|
import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
|
|
14
|
-
import {
|
|
14
|
+
import { _track } from "../../functions/track.js";
|
|
15
15
|
import RenderBlocks from "../render-blocks.svelte";
|
|
16
16
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
17
17
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
|
|
@@ -77,11 +77,14 @@ function evaluateJsCode() {
|
|
|
77
77
|
}
|
|
78
78
|
function onClick(_event) {
|
|
79
79
|
if (useContent()) {
|
|
80
|
-
|
|
80
|
+
const variationId = useContent?.()?.testVariationId;
|
|
81
|
+
const contentId = useContent?.()?.id;
|
|
82
|
+
_track({
|
|
81
83
|
type: "click",
|
|
82
84
|
canTrack: canTrackToUse(),
|
|
83
|
-
contentId
|
|
84
|
-
|
|
85
|
+
contentId,
|
|
86
|
+
apiKey: apiKey,
|
|
87
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
90
|
}
|
|
@@ -204,11 +207,14 @@ onMount(() => {
|
|
|
204
207
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
205
208
|
}
|
|
206
209
|
if (useContent()) {
|
|
207
|
-
|
|
210
|
+
const variationId = useContent?.()?.testVariationId;
|
|
211
|
+
const contentId = useContent?.()?.id;
|
|
212
|
+
_track({
|
|
208
213
|
type: "impression",
|
|
209
214
|
canTrack: canTrackToUse(),
|
|
210
|
-
contentId
|
|
211
|
-
|
|
215
|
+
contentId,
|
|
216
|
+
apiKey: apiKey,
|
|
217
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
212
218
|
});
|
|
213
219
|
}
|
|
214
220
|
// override normal content in preview mode
|
|
@@ -2,20 +2,50 @@ import type { CanTrack } from '../types/can-track.js';
|
|
|
2
2
|
interface Event {
|
|
3
3
|
type: 'click' | 'impression';
|
|
4
4
|
data: {
|
|
5
|
+
/**
|
|
6
|
+
* (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
|
|
7
|
+
*/
|
|
5
8
|
contentId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* This is the ID of the space that the content belongs to.
|
|
11
|
+
*/
|
|
6
12
|
ownerId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Stringified JSON object containing any additional metadata you want to track.
|
|
15
|
+
*/
|
|
7
16
|
metadata?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Session ID of the user. This is provided by the SDK by checking session storage.
|
|
19
|
+
*/
|
|
8
20
|
sessionId: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Visitor ID of the user. This is provided by the SDK by checking cookies.
|
|
23
|
+
*/
|
|
9
24
|
visitorId: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* (Optional) If running an A/B test, the ID of the variation that the user is in.
|
|
27
|
+
*/
|
|
28
|
+
variationId?: string;
|
|
10
29
|
[index: string]: any;
|
|
11
30
|
};
|
|
12
31
|
}
|
|
13
|
-
declare type EventProperties = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
declare type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | 'variationId'> & {
|
|
33
|
+
/**
|
|
34
|
+
* Your organization's API key.
|
|
35
|
+
*/
|
|
36
|
+
apiKey: Event['data']['ownerId'];
|
|
37
|
+
/**
|
|
38
|
+
* (Optional) metadata that you want to provide with your event.
|
|
39
|
+
*/
|
|
40
|
+
metadata?: {
|
|
41
|
+
[index: string]: any;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
45
|
+
*/
|
|
17
46
|
[index: string]: any;
|
|
18
47
|
};
|
|
19
48
|
export declare type EventProps = EventProperties & CanTrack;
|
|
20
|
-
export declare function
|
|
49
|
+
export declare function _track(eventProps: EventProps): Promise<void | Response>;
|
|
50
|
+
export declare const track: (args: EventProperties) => Promise<void | Response>;
|
|
21
51
|
export {};
|
|
@@ -14,16 +14,16 @@ const getTrackingEventData = async ({ canTrack, }) => {
|
|
|
14
14
|
visitorId,
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
const createEvent = async ({ type: eventType, canTrack,
|
|
17
|
+
const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...properties }) => ({
|
|
18
18
|
type: eventType,
|
|
19
19
|
data: {
|
|
20
20
|
...properties,
|
|
21
|
+
metadata: JSON.stringify(metadata),
|
|
21
22
|
...(await getTrackingEventData({ canTrack })),
|
|
22
|
-
ownerId:
|
|
23
|
-
contentId,
|
|
23
|
+
ownerId: apiKey,
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
|
-
export async function
|
|
26
|
+
export async function _track(eventProps) {
|
|
27
27
|
if (!eventProps.canTrack) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
@@ -46,3 +46,4 @@ export async function track(eventProps) {
|
|
|
46
46
|
console.error('Failed to track: ', err);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
export const track = (args) => _track({ ...args, canTrack: true });
|
package/package/index.d.ts
CHANGED
package/package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
components,
|
|
58
58
|
createRegisterComponentMessage,
|
|
59
59
|
} from "../../functions/register-component.js";
|
|
60
|
-
import {
|
|
60
|
+
import { _track } from "../../functions/track.js";
|
|
61
61
|
import RenderBlocks from "../render-blocks.svelte";
|
|
62
62
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
63
63
|
import {
|
|
@@ -131,11 +131,14 @@
|
|
|
131
131
|
}
|
|
132
132
|
function onClick(_event) {
|
|
133
133
|
if (useContent()) {
|
|
134
|
-
|
|
134
|
+
const variationId = useContent?.()?.testVariationId;
|
|
135
|
+
const contentId = useContent?.()?.id;
|
|
136
|
+
_track({
|
|
135
137
|
type: "click",
|
|
136
138
|
canTrack: canTrackToUse(),
|
|
137
|
-
contentId
|
|
138
|
-
|
|
139
|
+
contentId,
|
|
140
|
+
apiKey: apiKey,
|
|
141
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
139
142
|
});
|
|
140
143
|
}
|
|
141
144
|
}
|
|
@@ -275,11 +278,14 @@
|
|
|
275
278
|
);
|
|
276
279
|
}
|
|
277
280
|
if (useContent()) {
|
|
278
|
-
|
|
281
|
+
const variationId = useContent?.()?.testVariationId;
|
|
282
|
+
const contentId = useContent?.()?.id;
|
|
283
|
+
_track({
|
|
279
284
|
type: "impression",
|
|
280
285
|
canTrack: canTrackToUse(),
|
|
281
|
-
contentId
|
|
282
|
-
|
|
286
|
+
contentId,
|
|
287
|
+
apiKey: apiKey,
|
|
288
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
283
289
|
});
|
|
284
290
|
}
|
|
285
291
|
|
package/src/functions/track.ts
CHANGED
|
@@ -8,11 +8,30 @@ import { isEditing } from './is-editing.js';
|
|
|
8
8
|
interface Event {
|
|
9
9
|
type: 'click' | 'impression';
|
|
10
10
|
data: {
|
|
11
|
+
/**
|
|
12
|
+
* (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
|
|
13
|
+
*/
|
|
11
14
|
contentId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* This is the ID of the space that the content belongs to.
|
|
17
|
+
*/
|
|
12
18
|
ownerId: string;
|
|
19
|
+
/**
|
|
20
|
+
* Stringified JSON object containing any additional metadata you want to track.
|
|
21
|
+
*/
|
|
13
22
|
metadata?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Session ID of the user. This is provided by the SDK by checking session storage.
|
|
25
|
+
*/
|
|
14
26
|
sessionId: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Visitor ID of the user. This is provided by the SDK by checking cookies.
|
|
29
|
+
*/
|
|
15
30
|
visitorId: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* (Optional) If running an A/B test, the ID of the variation that the user is in.
|
|
33
|
+
*/
|
|
34
|
+
variationId?: string;
|
|
16
35
|
[index: string]: any;
|
|
17
36
|
};
|
|
18
37
|
}
|
|
@@ -38,32 +57,44 @@ const getTrackingEventData = async ({
|
|
|
38
57
|
};
|
|
39
58
|
};
|
|
40
59
|
|
|
41
|
-
type EventProperties =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
type EventProperties = Pick<Event, 'type'> &
|
|
61
|
+
Pick<Event['data'], 'contentId' | 'variationId'> & {
|
|
62
|
+
/**
|
|
63
|
+
* Your organization's API key.
|
|
64
|
+
*/
|
|
65
|
+
apiKey: Event['data']['ownerId'];
|
|
66
|
+
/**
|
|
67
|
+
* (Optional) metadata that you want to provide with your event.
|
|
68
|
+
*/
|
|
69
|
+
metadata?: {
|
|
70
|
+
[index: string]: any;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
75
|
+
*/
|
|
76
|
+
[index: string]: any;
|
|
77
|
+
};
|
|
47
78
|
|
|
48
79
|
export type EventProps = EventProperties & CanTrack;
|
|
49
80
|
|
|
50
81
|
const createEvent = async ({
|
|
51
82
|
type: eventType,
|
|
52
83
|
canTrack,
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
apiKey,
|
|
85
|
+
metadata,
|
|
55
86
|
...properties
|
|
56
87
|
}: EventProps): Promise<Event> => ({
|
|
57
88
|
type: eventType,
|
|
58
89
|
data: {
|
|
59
90
|
...properties,
|
|
91
|
+
metadata: JSON.stringify(metadata),
|
|
60
92
|
...(await getTrackingEventData({ canTrack })),
|
|
61
|
-
ownerId:
|
|
62
|
-
contentId,
|
|
93
|
+
ownerId: apiKey,
|
|
63
94
|
},
|
|
64
95
|
});
|
|
65
96
|
|
|
66
|
-
export async function
|
|
97
|
+
export async function _track(eventProps: EventProps) {
|
|
67
98
|
if (!eventProps.canTrack) {
|
|
68
99
|
return;
|
|
69
100
|
}
|
|
@@ -88,3 +119,6 @@ export async function track(eventProps: EventProps) {
|
|
|
88
119
|
console.error('Failed to track: ', err);
|
|
89
120
|
});
|
|
90
121
|
}
|
|
122
|
+
|
|
123
|
+
export const track = (args: EventProperties) =>
|
|
124
|
+
_track({ ...args, canTrack: true });
|
package/src/index.ts
CHANGED