@builder.io/sdk-solid 0.1.3-0 → 0.1.3

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.1.3-0",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/sdk-solid.js",
@@ -14,7 +14,7 @@ import {
14
14
  components,
15
15
  createRegisterComponentMessage,
16
16
  } from "../../functions/register-component.js";
17
- import { _track } from "../../functions/track.js";
17
+ import { _track } from "../../functions/track/index.js";
18
18
  import RenderBlocks from "../render-blocks.jsx";
19
19
  import RenderContentStyles from "./components/render-styles.jsx";
20
20
  import builderContext from "../../context/builder.context.js";
@@ -23,6 +23,7 @@ import {
23
23
  setupBrowserForEditing,
24
24
  } from "../../scripts/init-editing.js";
25
25
  import { checkIsDefined } from "../../helpers/nullable.js";
26
+ import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
26
27
 
27
28
  function RenderContent(props) {
28
29
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -62,6 +63,8 @@ function RenderContent(props) {
62
63
 
63
64
  const [httpReqsData, setHttpReqsData] = createSignal({});
64
65
 
66
+ const [clicked, setClicked] = createSignal(false);
67
+
65
68
  function contentState() {
66
69
  return {
67
70
  ...props.content?.data?.state,
@@ -124,7 +127,7 @@ function RenderContent(props) {
124
127
  }
125
128
  }
126
129
 
127
- function onClick(_event) {
130
+ function onClick(event) {
128
131
  if (useContent) {
129
132
  const variationId = useContent?.testVariationId;
130
133
  const contentId = useContent?.id;
@@ -134,8 +137,13 @@ function RenderContent(props) {
134
137
  contentId,
135
138
  apiKey: props.apiKey,
136
139
  variationId: variationId !== contentId ? variationId : undefined,
140
+ ...getInteractionPropertiesForEvent(event),
141
+ unique: !clicked(),
137
142
  });
138
143
  }
144
+ if (!clicked()) {
145
+ setClicked(true);
146
+ }
139
147
  }
140
148
 
141
149
  function evalExpression(expression) {
@@ -0,0 +1,50 @@
1
+ import { TARGET } from "../../constants/target";
2
+ import { isBrowser } from "../is-browser";
3
+ const getLocation = () => {
4
+ if (TARGET === "reactNative") {
5
+ return null;
6
+ } else if (isBrowser()) {
7
+ const parsedLocation = new URL(location.href);
8
+ if (parsedLocation.pathname === "") {
9
+ parsedLocation.pathname = "/";
10
+ }
11
+ return parsedLocation;
12
+ } else {
13
+ console.warn("Cannot get location for tracking in non-browser environment");
14
+ return null;
15
+ }
16
+ };
17
+ const getUserAgent = () => typeof navigator === "object" && navigator.userAgent || "";
18
+ const getUserAttributes = () => {
19
+ const userAgent = getUserAgent();
20
+ const isMobile = {
21
+ Android() {
22
+ return userAgent.match(/Android/i);
23
+ },
24
+ BlackBerry() {
25
+ return userAgent.match(/BlackBerry/i);
26
+ },
27
+ iOS() {
28
+ return userAgent.match(/iPhone|iPod/i);
29
+ },
30
+ Opera() {
31
+ return userAgent.match(/Opera Mini/i);
32
+ },
33
+ Windows() {
34
+ return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
35
+ },
36
+ any() {
37
+ return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows() || TARGET === "reactNative";
38
+ }
39
+ };
40
+ const isTablet = userAgent.match(/Tablet|iPad/i);
41
+ const url = getLocation();
42
+ return {
43
+ urlPath: url == null ? void 0 : url.pathname,
44
+ host: (url == null ? void 0 : url.host) || (url == null ? void 0 : url.hostname),
45
+ device: isTablet ? "tablet" : isMobile.any() ? "mobile" : "desktop"
46
+ };
47
+ };
48
+ export {
49
+ getUserAttributes
50
+ };
@@ -49,11 +49,12 @@ var __async = (__this, __arguments, generator) => {
49
49
  step((generator = generator.apply(__this, __arguments)).next());
50
50
  });
51
51
  };
52
- import { TARGET } from "../constants/target.js";
53
- import { getSessionId } from "../helpers/sessionId.js";
54
- import { getVisitorId } from "../helpers/visitorId.js";
55
- import { isBrowser } from "./is-browser.js";
56
- import { isEditing } from "./is-editing.js";
52
+ import { TARGET } from "../../constants/target.js";
53
+ import { getSessionId } from "../../helpers/sessionId.js";
54
+ import { getVisitorId } from "../../helpers/visitorId.js";
55
+ import { isBrowser } from "../is-browser.js";
56
+ import { isEditing } from "../is-editing.js";
57
+ import { getUserAttributes } from "./helpers.js";
57
58
  const getTrackingEventData = (_0) => __async(void 0, [_0], function* ({
58
59
  canTrack
59
60
  }) {
@@ -82,8 +83,11 @@ const createEvent = (_a) => __async(void 0, null, function* () {
82
83
  return {
83
84
  type: eventType,
84
85
  data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, properties), {
85
- metadata: JSON.stringify(metadata)
86
+ metadata: __spreadValues({
87
+ url: location.href
88
+ }, metadata)
86
89
  }), yield getTrackingEventData({ canTrack })), {
90
+ userAttributes: getUserAttributes(),
87
91
  ownerId: apiKey
88
92
  })
89
93
  };
@@ -0,0 +1,53 @@
1
+ function round(num) {
2
+ return Math.round(num * 1e3) / 1e3;
3
+ }
4
+ const findParentElement = (target, callback, checkElement = true) => {
5
+ if (!(target instanceof HTMLElement)) {
6
+ return null;
7
+ }
8
+ let parent = checkElement ? target : target.parentElement;
9
+ do {
10
+ if (!parent) {
11
+ return null;
12
+ }
13
+ const matches = callback(parent);
14
+ if (matches) {
15
+ return parent;
16
+ }
17
+ } while (parent = parent.parentElement);
18
+ return null;
19
+ };
20
+ const findBuilderParent = (target) => findParentElement(target, (el) => {
21
+ const id = el.getAttribute("builder-id") || el.id;
22
+ return Boolean((id == null ? void 0 : id.indexOf("builder-")) === 0);
23
+ });
24
+ const computeOffset = ({
25
+ event,
26
+ target
27
+ }) => {
28
+ const targetRect = target.getBoundingClientRect();
29
+ const xOffset = event.clientX - targetRect.left;
30
+ const yOffset = event.clientY - targetRect.top;
31
+ const xRatio = round(xOffset / targetRect.width);
32
+ const yRatio = round(yOffset / targetRect.height);
33
+ return {
34
+ x: xRatio,
35
+ y: yRatio
36
+ };
37
+ };
38
+ const getInteractionPropertiesForEvent = (event) => {
39
+ const target = event.target;
40
+ const targetBuilderElement = target && findBuilderParent(target);
41
+ const builderId = (targetBuilderElement == null ? void 0 : targetBuilderElement.getAttribute("builder-id")) || (targetBuilderElement == null ? void 0 : targetBuilderElement.id);
42
+ return {
43
+ targetBuilderElement: builderId || void 0,
44
+ metadata: {
45
+ targetOffset: target ? computeOffset({ event, target }) : void 0,
46
+ builderTargetOffset: targetBuilderElement ? computeOffset({ event, target: targetBuilderElement }) : void 0,
47
+ builderElementIndex: targetBuilderElement && builderId ? [].slice.call(document.getElementsByClassName(builderId)).indexOf(targetBuilderElement) : void 0
48
+ }
49
+ };
50
+ };
51
+ export {
52
+ getInteractionPropertiesForEvent
53
+ };
package/src/index.js CHANGED
@@ -8,7 +8,7 @@ export * from "./functions/register.js";
8
8
  export * from "./functions/set-editor-settings.js";
9
9
  export * from "./functions/get-content/index.js";
10
10
  export * from "./functions/get-builder-search-params/index.js";
11
- import { track } from "./functions/track";
11
+ import { track } from "./functions/track/index.js";
12
12
  export {
13
13
  track
14
14
  };