@solomon-tech/webanalytics-sdk 1.0.3 → 1.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.
@@ -3,10 +3,15 @@ import type { CustomAliases } from "../core/types";
3
3
  export interface NodeSDKConfig {
4
4
  companyId: string;
5
5
  debug?: boolean;
6
+ identifyByAlias?: boolean;
7
+ useTouchpoint?: boolean;
6
8
  webanalyticsUrl?: string;
9
+ pixelUrl?: string;
10
+ userAgent?: string;
7
11
  }
8
12
  export declare class SolomonSDK {
9
13
  private config;
10
14
  constructor(config: NodeSDKConfig);
11
15
  track<E extends SolomonEvent>(event: E, payload?: SolomonPayload<E>, aliases?: CustomAliases): Promise<void>;
16
+ private buildTouchpointEvent;
12
17
  }
@@ -8,12 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { randomUUID } from "crypto";
11
- const DEFAULT_URL = "https://pixel.solomon.com.br/event";
11
+ const DEFAULT_WEBANALYTICS_URL = "https://webanalytics.solomon.com.br/event?mode=web";
12
+ const DEFAULT_PIXEL_URL = "https://pixel.solomon.com.br/event";
13
+ const DEFAULT_USER_AGENT = "Mozilla/5.0 (compatible; SolomonSDK-Node/1.0.6)";
14
+ const BRENDI_COMPANY_ID = "G6fGRIcYL8qJ06SukNdV";
15
+ const DUMMY_SESSION_ID = "00000000-0000-4000-8000-000000000000";
12
16
  export class SolomonSDK {
13
17
  constructor(config) {
14
18
  this.config = config;
15
19
  if (this.config.debug) {
16
- console.log("[SolomonSDK:Node] initialized", config);
20
+ console.log("[SolomonSDK:Node] initialized", {
21
+ companyId: config.companyId,
22
+ useTouchpoint: config.useTouchpoint,
23
+ });
17
24
  }
18
25
  }
19
26
  track(event, payload, aliases) {
@@ -21,12 +28,17 @@ export class SolomonSDK {
21
28
  if (this.config.debug) {
22
29
  console.log("[SolomonSDK:Node] Tracking event:", event, payload);
23
30
  }
31
+ const identifyByAlias = this.config.identifyByAlias || this.config.companyId === BRENDI_COMPANY_ID;
32
+ const userId = (identifyByAlias && (aliases === null || aliases === void 0 ? void 0 : aliases.user_id)) ? aliases.user_id : randomUUID();
24
33
  const eventData = {
25
34
  company_id: this.config.companyId,
26
35
  event_id: randomUUID(),
27
36
  event_time: new Date().toISOString(),
28
- session_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || randomUUID(),
29
- user_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || randomUUID(),
37
+ session_id: DUMMY_SESSION_ID,
38
+ user_id: userId,
39
+ fbp: "",
40
+ fbc: "",
41
+ legacy_id: "",
30
42
  custom_aliases: {
31
43
  user_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || "",
32
44
  email: (aliases === null || aliases === void 0 ? void 0 : aliases.email) || "",
@@ -48,21 +60,39 @@ export class SolomonSDK {
48
60
  sol_campaign: "",
49
61
  sol_content: "",
50
62
  event_payload: payload || {},
51
- fbp: "",
52
- fbc: "",
63
+ voxus_url: "",
64
+ };
65
+ const webanalyticsUrl = this.config.webanalyticsUrl || DEFAULT_WEBANALYTICS_URL;
66
+ const pixelUrl = this.config.pixelUrl || DEFAULT_PIXEL_URL;
67
+ const headers = {
68
+ "Content-Type": "application/json",
69
+ "User-Agent": this.config.userAgent || DEFAULT_USER_AGENT,
53
70
  };
54
- const url = this.config.webanalyticsUrl || DEFAULT_URL;
55
71
  try {
56
- const response = yield fetch(url, {
57
- method: "POST",
58
- headers: { "Content-Type": "application/json" },
59
- body: JSON.stringify(eventData),
60
- });
61
- if (!response.ok) {
62
- throw new Error(`HTTP ${response.status}: ${yield response.text()}`);
72
+ const promises = [
73
+ fetch(webanalyticsUrl, {
74
+ method: "POST",
75
+ headers,
76
+ body: JSON.stringify(eventData),
77
+ }),
78
+ ];
79
+ if (this.config.useTouchpoint) {
80
+ const touchpointData = this.buildTouchpointEvent(userId);
81
+ promises.push(fetch(pixelUrl, {
82
+ method: "POST",
83
+ headers,
84
+ body: JSON.stringify(touchpointData),
85
+ }));
86
+ }
87
+ const responses = yield Promise.all(promises);
88
+ if (!responses[0].ok) {
89
+ throw new Error(`Event HTTP ${responses[0].status}: ${yield responses[0].text()}`);
90
+ }
91
+ if (responses[1] && !responses[1].ok) {
92
+ console.error(`[SolomonSDK:Node] Touchpoint HTTP ${responses[1].status}: ${yield responses[1].text()}`);
63
93
  }
64
94
  if (this.config.debug) {
65
- console.log("[SolomonSDK:Node] Event sent:", event);
95
+ console.log("[SolomonSDK:Node] Event sent:", event, this.config.useTouchpoint ? "(+ touchpoint)" : "");
66
96
  }
67
97
  }
68
98
  catch (error) {
@@ -71,4 +101,39 @@ export class SolomonSDK {
71
101
  }
72
102
  });
73
103
  }
104
+ buildTouchpointEvent(userId) {
105
+ return {
106
+ id: userId,
107
+ referrer: "",
108
+ path: "",
109
+ utm_source: "",
110
+ utm_medium: "",
111
+ utm_campaign: "",
112
+ utm_term: userId,
113
+ utm_content: "",
114
+ sol_source: "",
115
+ sol_medium: "",
116
+ sol_campaign: "",
117
+ sol_content: "",
118
+ fbp: "",
119
+ fbc: "",
120
+ ga_id: "",
121
+ fbclid: "",
122
+ locale: "",
123
+ timezone: "",
124
+ osVersion: "",
125
+ screenWidth: 0,
126
+ screenHeight: 0,
127
+ density: 1,
128
+ cpuCores: 0,
129
+ queryParams: "",
130
+ debug: "",
131
+ old_id: "",
132
+ shopify_id: this.config.companyId,
133
+ current_domain: "",
134
+ cart_token: userId,
135
+ email: "",
136
+ utmsTrack: "",
137
+ };
138
+ }
74
139
  }
@@ -1,5 +1,5 @@
1
1
  export { SolomonSDK } from "./client";
2
2
  export type { NodeSDKConfig } from "./client";
3
3
  export type { SolomonEvent, SolomonPayload } from "../core/events";
4
- export type { CustomAliases } from "../core/types";
4
+ export type { CustomAliases, Product } from "../core/types";
5
5
  export { SolomonSDK as default } from "./client";
@@ -1 +1 @@
1
- import{createRequire as o}from"node:module";var e={d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(o,e)=>Object.prototype.hasOwnProperty.call(o,e)},t={};e.d(t,{C:()=>SolomonSDK,A:()=>SolomonSDK});const n=o(import.meta.url)("crypto");var __awaiter=function(o,e,t,n){return new(t||(t=Promise))((function(i,r){function fulfilled(o){try{step(n.next(o))}catch(o){r(o)}}function rejected(o){try{step(n.throw(o))}catch(o){r(o)}}function step(o){var e;o.done?i(o.value):(e=o.value,e instanceof t?e:new t((function(o){o(e)}))).then(fulfilled,rejected)}step((n=n.apply(o,e||[])).next())}))};class SolomonSDK{constructor(o){this.config=o,this.config.debug&&console.log("[SolomonSDK:Node] initialized",o)}track(o,e,t){return __awaiter(this,void 0,void 0,(function*(){this.config.debug&&console.log("[SolomonSDK:Node] Tracking event:",o,e);const i={company_id:this.config.companyId,event_id:(0,n.randomUUID)(),event_time:(new Date).toISOString(),session_id:(null==t?void 0:t.user_id)||(0,n.randomUUID)(),user_id:(null==t?void 0:t.user_id)||(0,n.randomUUID)(),custom_aliases:{user_id:(null==t?void 0:t.user_id)||"",email:(null==t?void 0:t.email)||"",phone:(null==t?void 0:t.phone)||"",customer_id:(null==t?void 0:t.customer_id)||"",cart_token:(null==t?void 0:t.cart_token)||"",order_id:(null==t?void 0:t.order_id)||""},event_type:o,page_referrer:"",page_path:"",utm_source:"",utm_medium:"",utm_campaign:"",utm_term:"",utm_content:"",sol_source:"",sol_medium:"",sol_campaign:"",sol_content:"",event_payload:e||{},fbp:"",fbc:""},r=this.config.webanalyticsUrl||"https://pixel.solomon.com.br/event";try{const e=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!e.ok)throw new Error(`HTTP ${e.status}: ${yield e.text()}`);this.config.debug&&console.log("[SolomonSDK:Node] Event sent:",o)}catch(o){throw console.error("[SolomonSDK:Node] Error sending event:",o),o}}))}}var i=t.C,r=t.A;export{i as SolomonSDK,r as default};
1
+ import{createRequire as o}from"node:module";var e={d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(o,e)=>Object.prototype.hasOwnProperty.call(o,e)},t={};e.d(t,{C:()=>SolomonSDK,A:()=>SolomonSDK});const n=o(import.meta.url)("crypto");var __awaiter=function(o,e,t,n){return new(t||(t=Promise))((function(i,r){function fulfilled(o){try{step(n.next(o))}catch(o){r(o)}}function rejected(o){try{step(n.throw(o))}catch(o){r(o)}}function step(o){var e;o.done?i(o.value):(e=o.value,e instanceof t?e:new t((function(o){o(e)}))).then(fulfilled,rejected)}step((n=n.apply(o,e||[])).next())}))};class SolomonSDK{constructor(o){this.config=o,this.config.debug&&console.log("[SolomonSDK:Node] initialized",{companyId:o.companyId,useTouchpoint:o.useTouchpoint})}track(o,e,t){return __awaiter(this,void 0,void 0,(function*(){this.config.debug&&console.log("[SolomonSDK:Node] Tracking event:",o,e);const i=(this.config.identifyByAlias||"G6fGRIcYL8qJ06SukNdV"===this.config.companyId)&&(null==t?void 0:t.user_id)?t.user_id:(0,n.randomUUID)(),r={company_id:this.config.companyId,event_id:(0,n.randomUUID)(),event_time:(new Date).toISOString(),session_id:"00000000-0000-4000-8000-000000000000",user_id:i,fbp:"",fbc:"",legacy_id:"",custom_aliases:{user_id:(null==t?void 0:t.user_id)||"",email:(null==t?void 0:t.email)||"",phone:(null==t?void 0:t.phone)||"",customer_id:(null==t?void 0:t.customer_id)||"",cart_token:(null==t?void 0:t.cart_token)||"",order_id:(null==t?void 0:t.order_id)||""},event_type:o,page_referrer:"",page_path:"",utm_source:"",utm_medium:"",utm_campaign:"",utm_term:"",utm_content:"",sol_source:"",sol_medium:"",sol_campaign:"",sol_content:"",event_payload:e||{},voxus_url:""},c=this.config.webanalyticsUrl||"https://webanalytics.solomon.com.br/event?mode=web",s=this.config.pixelUrl||"https://pixel.solomon.com.br/event",l={"Content-Type":"application/json","User-Agent":this.config.userAgent||"Mozilla/5.0 (compatible; SolomonSDK-Node/1.0.6)"};try{const e=[fetch(c,{method:"POST",headers:l,body:JSON.stringify(r)})];if(this.config.useTouchpoint){const o=this.buildTouchpointEvent(i);e.push(fetch(s,{method:"POST",headers:l,body:JSON.stringify(o)}))}const t=yield Promise.all(e);if(!t[0].ok)throw new Error(`Event HTTP ${t[0].status}: ${yield t[0].text()}`);t[1]&&!t[1].ok&&console.error(`[SolomonSDK:Node] Touchpoint HTTP ${t[1].status}: ${yield t[1].text()}`),this.config.debug&&console.log("[SolomonSDK:Node] Event sent:",o,this.config.useTouchpoint?"(+ touchpoint)":"")}catch(o){throw console.error("[SolomonSDK:Node] Error sending event:",o),o}}))}buildTouchpointEvent(o){return{id:o,referrer:"",path:"",utm_source:"",utm_medium:"",utm_campaign:"",utm_term:o,utm_content:"",sol_source:"",sol_medium:"",sol_campaign:"",sol_content:"",fbp:"",fbc:"",ga_id:"",fbclid:"",locale:"",timezone:"",osVersion:"",screenWidth:0,screenHeight:0,density:1,cpuCores:0,queryParams:"",debug:"",old_id:"",shopify_id:this.config.companyId,current_domain:"",cart_token:o,email:"",utmsTrack:""}}}var i=t.C,r=t.A;export{i as SolomonSDK,r as default};
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@solomon-tech/webanalytics-sdk/node",
3
+ "main": "../dist/sdk/solomon-sdk.node.esm.min.js",
4
+ "module": "../dist/sdk/solomon-sdk.node.esm.min.js",
5
+ "types": "../dist/sdk/sdk/node/index.d.ts",
6
+ "sideEffects": false,
7
+ "type": "module"
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solomon-tech/webanalytics-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Solomon WebAnalytics SDK — browser and Node.js event tracking",
5
5
  "main": "./dist/sdk/solomon-sdk.esm.min.js",
6
6
  "types": "./dist/sdk/sdk/index.d.ts",
@@ -15,7 +15,8 @@
15
15
  }
16
16
  },
17
17
  "files": [
18
- "dist/sdk"
18
+ "dist/sdk",
19
+ "node"
19
20
  ],
20
21
  "scripts": {
21
22
  "watch": "webpack -w",