@solomon-tech/webanalytics-sdk 1.0.0 → 1.0.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.
@@ -1,13 +1,12 @@
1
1
  import type { SolomonEvent, SolomonPayload } from "../core/events";
2
2
  import type { CustomAliases } from "../core/types";
3
- import type { SDKConfig } from "../core/client";
4
- export interface NodeSDKConfig extends SDKConfig {
3
+ export interface NodeSDKConfig {
4
+ companyId: string;
5
+ debug?: boolean;
5
6
  webanalyticsUrl?: string;
6
- pixelUrl?: string;
7
7
  }
8
8
  export declare class SolomonSDK {
9
9
  private config;
10
10
  constructor(config: NodeSDKConfig);
11
11
  track<E extends SolomonEvent>(event: E, payload?: SolomonPayload<E>, aliases?: CustomAliases): Promise<void>;
12
- private sendTouchpoint;
13
12
  }
@@ -8,8 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { randomUUID } from "crypto";
11
- const WEBANALYTICS_URL = "https://pixel.solomon.com.br/event";
12
- const PIXEL_URL = "https://webanalytics.solomon.com.br/event?mode=web";
11
+ const DEFAULT_URL = "https://pixel.solomon.com.br/event";
13
12
  export class SolomonSDK {
14
13
  constructor(config) {
15
14
  this.config = config;
@@ -52,9 +51,9 @@ export class SolomonSDK {
52
51
  fbp: "",
53
52
  fbc: "",
54
53
  };
55
- const webanalyticsUrl = this.config.webanalyticsUrl || WEBANALYTICS_URL;
54
+ const url = this.config.webanalyticsUrl || DEFAULT_URL;
56
55
  try {
57
- const response = yield fetch(webanalyticsUrl, {
56
+ const response = yield fetch(url, {
58
57
  method: "POST",
59
58
  headers: { "Content-Type": "application/json" },
60
59
  body: JSON.stringify(eventData),
@@ -63,72 +62,13 @@ export class SolomonSDK {
63
62
  throw new Error(`HTTP ${response.status}: ${yield response.text()}`);
64
63
  }
65
64
  if (this.config.debug) {
66
- console.log("[SolomonSDK:Node] Event sent to webanalytics:", event);
65
+ console.log("[SolomonSDK:Node] Event sent:", event);
67
66
  }
68
67
  }
69
68
  catch (error) {
70
69
  console.error("[SolomonSDK:Node] Error sending event:", error);
71
70
  throw error;
72
71
  }
73
- if (this.config.useTouchpoint) {
74
- yield this.sendTouchpoint(eventData);
75
- }
76
- });
77
- }
78
- sendTouchpoint(eventData) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- var _a, _b;
81
- const pixelUrl = this.config.pixelUrl || PIXEL_URL;
82
- const touchpointData = {
83
- id: randomUUID(),
84
- referrer: "",
85
- path: "",
86
- utm_source: eventData.utm_source,
87
- utm_medium: eventData.utm_medium,
88
- utm_campaign: eventData.utm_campaign,
89
- utm_term: randomUUID(),
90
- utm_content: eventData.utm_content,
91
- sol_source: eventData.sol_source,
92
- sol_medium: eventData.sol_medium,
93
- sol_campaign: eventData.sol_campaign,
94
- sol_content: eventData.sol_content,
95
- fbp: "",
96
- fbc: "",
97
- ga_id: "",
98
- fbclid: "",
99
- locale: "",
100
- timezone: "",
101
- osVersion: "",
102
- screenWidth: 0,
103
- screenHeight: 0,
104
- density: 1,
105
- cpuCores: 0,
106
- queryParams: "",
107
- debug: "",
108
- old_id: "",
109
- shopify_id: this.config.companyId,
110
- current_domain: "",
111
- cart_token: ((_a = eventData.custom_aliases) === null || _a === void 0 ? void 0 : _a.user_id) || "",
112
- email: ((_b = eventData.custom_aliases) === null || _b === void 0 ? void 0 : _b.email) || "",
113
- };
114
- try {
115
- const response = yield fetch(pixelUrl, {
116
- method: "POST",
117
- headers: { "Content-Type": "application/json" },
118
- body: JSON.stringify(touchpointData),
119
- });
120
- if (!response.ok && this.config.debug) {
121
- console.warn("[SolomonSDK:Node] Touchpoint send failed:", response.status);
122
- }
123
- else if (this.config.debug) {
124
- console.log("[SolomonSDK:Node] Touchpoint sent");
125
- }
126
- }
127
- catch (error) {
128
- if (this.config.debug) {
129
- console.warn("[SolomonSDK:Node] Touchpoint error:", error);
130
- }
131
- }
132
72
  });
133
73
  }
134
74
  }
@@ -1,7 +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, Product } from "../core/types";
5
- export type { SDKConfig } from "../core/client";
6
- export type { ViewContentPayload, AddToCartPayload, InitiateCheckoutPayload, AddShippingInfoPayload, AddCustomerInfoPayload, AddPaymentInfoPayload, CheckoutCompletedPayload } from "../core/events";
4
+ export type { CustomAliases } from "../core/types";
7
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,s){function fulfilled(o){try{step(n.next(o))}catch(o){s(o)}}function rejected(o){try{step(n.throw(o))}catch(o){s(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:""},s=this.config.webanalyticsUrl||"https://pixel.solomon.com.br/event";try{const e=yield fetch(s,{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 to webanalytics:",o)}catch(o){throw console.error("[SolomonSDK:Node] Error sending event:",o),o}this.config.useTouchpoint&&(yield this.sendTouchpoint(i))}))}sendTouchpoint(o){return __awaiter(this,void 0,void 0,(function*(){var e,t;const i=this.config.pixelUrl||"https://webanalytics.solomon.com.br/event?mode=web",s={id:(0,n.randomUUID)(),referrer:"",path:"",utm_source:o.utm_source,utm_medium:o.utm_medium,utm_campaign:o.utm_campaign,utm_term:(0,n.randomUUID)(),utm_content:o.utm_content,sol_source:o.sol_source,sol_medium:o.sol_medium,sol_campaign:o.sol_campaign,sol_content:o.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:(null===(e=o.custom_aliases)||void 0===e?void 0:e.user_id)||"",email:(null===(t=o.custom_aliases)||void 0===t?void 0:t.email)||""};try{const o=yield fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});!o.ok&&this.config.debug?console.warn("[SolomonSDK:Node] Touchpoint send failed:",o.status):this.config.debug&&console.log("[SolomonSDK:Node] Touchpoint sent")}catch(o){this.config.debug&&console.warn("[SolomonSDK:Node] Touchpoint error:",o)}}))}}var i=t.C,s=t.A;export{i as SolomonSDK,s 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",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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solomon-tech/webanalytics-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",