@g2crowd/buyer-intent-provider-sdk 0.3.0 → 0.4.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/browser/dom.js DELETED
@@ -1,98 +0,0 @@
1
- function parseJson(value) {
2
- if (!value) {
3
- return undefined;
4
- }
5
-
6
- try {
7
- return JSON.parse(value);
8
- } catch (_error) {
9
- return undefined;
10
- }
11
- }
12
-
13
- function parseArray(value) {
14
- if (!value) {
15
- return undefined;
16
- }
17
-
18
- const parsed = parseJson(value);
19
- if (Array.isArray(parsed)) {
20
- return parsed;
21
- }
22
-
23
- if (typeof value === 'string') {
24
- return value
25
- .split(',')
26
- .map((entry) => entry.trim())
27
- .filter(Boolean);
28
- }
29
-
30
- return undefined;
31
- }
32
-
33
- function readTagElement(element) {
34
- if (!element) {
35
- return undefined;
36
- }
37
-
38
- if (element.tagName === 'SCRIPT') {
39
- const parsed =
40
- parseJson(element.textContent || '') ||
41
- parseJson(element.getAttribute('data-buyer-intent'));
42
- if (parsed && typeof parsed === 'object') {
43
- return parsed;
44
- }
45
- }
46
-
47
- const dataJson = parseJson(element.getAttribute('data-buyer-intent'));
48
- if (dataJson && typeof dataJson === 'object') {
49
- return dataJson;
50
- }
51
-
52
- const dataset = element.dataset || {};
53
- return {
54
- productIds: parseArray(dataset.productIds),
55
- categoryIds: parseArray(dataset.categoryIds),
56
- tag: dataset.tag,
57
- sourceLocation: dataset.sourceLocation,
58
- context: parseJson(dataset.context),
59
- };
60
- }
61
-
62
- export function readTags(elements) {
63
- if (typeof document === 'undefined') {
64
- return [];
65
- }
66
-
67
- const found = elements || new Set();
68
- const legacy = document.getElementById('buyer-intent-tags');
69
- if (legacy) {
70
- found.add(legacy);
71
- }
72
-
73
- document.querySelectorAll('[data-buyer-intent]').forEach((element) => {
74
- found.add(element);
75
- });
76
-
77
- return Array.from(found)
78
- .map((element) => ({ element, tag: readTagElement(element) }))
79
- .filter((entry) => entry.tag && typeof entry.tag === 'object');
80
- }
81
-
82
- export function readElementConfig(element) {
83
- if (!element || !element.dataset) {
84
- return {};
85
- }
86
-
87
- const { origin, userType, distinctId, activityEndpoint } = element.dataset;
88
-
89
- return { origin, userType, distinctId, activityEndpoint };
90
- }
91
-
92
- export function resolveEventName(element, fallback) {
93
- if (element && element.dataset && element.dataset.eventName) {
94
- return element.dataset.eventName;
95
- }
96
-
97
- return fallback;
98
- }
@@ -1 +0,0 @@
1
- export { BuyerIntentViewElement, BuyerIntentClickElement } from './base.js';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes