@solomon-tech/webanalytics-sdk 1.0.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/README.md +20 -0
- package/dist/sdk/cookies/fbp.d.ts +3 -0
- package/dist/sdk/cookies/fbp.js +21 -0
- package/dist/sdk/cookies/legacy.d.ts +2 -0
- package/dist/sdk/cookies/legacy.js +16 -0
- package/dist/sdk/cookies/session.d.ts +2 -0
- package/dist/sdk/cookies/session.js +25 -0
- package/dist/sdk/cookies/user.d.ts +2 -0
- package/dist/sdk/cookies/user.js +25 -0
- package/dist/sdk/cookies/uuid.d.ts +0 -0
- package/dist/sdk/cookies/uuid.js +1 -0
- package/dist/sdk/events.d.ts +292 -0
- package/dist/sdk/events.js +366 -0
- package/dist/sdk/publish.d.ts +3 -0
- package/dist/sdk/publish.js +78 -0
- package/dist/sdk/sdk/core/client.d.ts +12 -0
- package/dist/sdk/sdk/core/client.js +81 -0
- package/dist/sdk/sdk/core/events.d.ts +52 -0
- package/dist/sdk/sdk/core/events.js +1 -0
- package/dist/sdk/sdk/core/types.d.ts +15 -0
- package/dist/sdk/sdk/core/types.js +1 -0
- package/dist/sdk/sdk/index.d.ts +6 -0
- package/dist/sdk/sdk/index.js +2 -0
- package/dist/sdk/sdk/node/client.d.ts +13 -0
- package/dist/sdk/sdk/node/client.js +134 -0
- package/dist/sdk/sdk/node/index.d.ts +7 -0
- package/dist/sdk/sdk/node/index.js +2 -0
- package/dist/sdk/solomon-sdk.esm.min.js +1 -0
- package/dist/sdk/solomon-sdk.min.js +1 -0
- package/dist/sdk/solomon-sdk.node.esm.min.js +1 -0
- package/dist/sdk/utils.d.ts +11 -0
- package/dist/sdk/utils.js +208 -0
- package/package.json +69 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
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";
|
|
13
|
+
export class SolomonSDK {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
if (this.config.debug) {
|
|
17
|
+
console.log("[SolomonSDK:Node] initialized", config);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
track(event, payload, aliases) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (this.config.debug) {
|
|
23
|
+
console.log("[SolomonSDK:Node] Tracking event:", event, payload);
|
|
24
|
+
}
|
|
25
|
+
const eventData = {
|
|
26
|
+
company_id: this.config.companyId,
|
|
27
|
+
event_id: randomUUID(),
|
|
28
|
+
event_time: new Date().toISOString(),
|
|
29
|
+
session_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || randomUUID(),
|
|
30
|
+
user_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || randomUUID(),
|
|
31
|
+
custom_aliases: {
|
|
32
|
+
user_id: (aliases === null || aliases === void 0 ? void 0 : aliases.user_id) || "",
|
|
33
|
+
email: (aliases === null || aliases === void 0 ? void 0 : aliases.email) || "",
|
|
34
|
+
phone: (aliases === null || aliases === void 0 ? void 0 : aliases.phone) || "",
|
|
35
|
+
customer_id: (aliases === null || aliases === void 0 ? void 0 : aliases.customer_id) || "",
|
|
36
|
+
cart_token: (aliases === null || aliases === void 0 ? void 0 : aliases.cart_token) || "",
|
|
37
|
+
order_id: (aliases === null || aliases === void 0 ? void 0 : aliases.order_id) || "",
|
|
38
|
+
},
|
|
39
|
+
event_type: event,
|
|
40
|
+
page_referrer: "",
|
|
41
|
+
page_path: "",
|
|
42
|
+
utm_source: "",
|
|
43
|
+
utm_medium: "",
|
|
44
|
+
utm_campaign: "",
|
|
45
|
+
utm_term: "",
|
|
46
|
+
utm_content: "",
|
|
47
|
+
sol_source: "",
|
|
48
|
+
sol_medium: "",
|
|
49
|
+
sol_campaign: "",
|
|
50
|
+
sol_content: "",
|
|
51
|
+
event_payload: payload || {},
|
|
52
|
+
fbp: "",
|
|
53
|
+
fbc: "",
|
|
54
|
+
};
|
|
55
|
+
const webanalyticsUrl = this.config.webanalyticsUrl || WEBANALYTICS_URL;
|
|
56
|
+
try {
|
|
57
|
+
const response = yield fetch(webanalyticsUrl, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { "Content-Type": "application/json" },
|
|
60
|
+
body: JSON.stringify(eventData),
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new Error(`HTTP ${response.status}: ${yield response.text()}`);
|
|
64
|
+
}
|
|
65
|
+
if (this.config.debug) {
|
|
66
|
+
console.log("[SolomonSDK:Node] Event sent to webanalytics:", event);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error("[SolomonSDK:Node] Error sending event:", error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
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
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { SolomonSDK } from "./client";
|
|
2
|
+
export type { NodeSDKConfig } from "./client";
|
|
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";
|
|
7
|
+
export { SolomonSDK as default } from "./client";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o={d:(e,n)=>{for(var i in n)o.o(n,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(o,e)=>Object.prototype.hasOwnProperty.call(o,e)},e={};o.d(e,{C:()=>SolomonSDK,A:()=>SolomonSDK});var __awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const getCookie=o=>__awaiter(void 0,void 0,void 0,(function*(){if((null===self||void 0===self?void 0:self.Shopify)&&(null===self||void 0===self?void 0:self.Shopify.browser)){const e=yield self.Shopify.browser.cookie.get(o);return e?decodeURIComponent(e):null}{if(!document.cookie||""===document.cookie)return null;const e=document.cookie.split(";");for(let n=0;n<e.length;n++){const i=e[n].trim();if(i.substring(0,o.length+1)===o+"=")return decodeURIComponent(i.substring(o.length+1))}return null}})),getLocalStorage=o=>__awaiter(void 0,void 0,void 0,(function*(){var e;return(null===(e=null===self||void 0===self?void 0:self.Shopify)||void 0===e?void 0:e.browser)?yield self.Shopify.browser.localStorage.getItem(o):localStorage.getItem(o)})),getAllStorage=o=>__awaiter(void 0,void 0,void 0,(function*(){return(yield getLocalStorage(o))||(yield getCookie(o))})),setCookie=(o,e,n,i)=>__awaiter(void 0,void 0,void 0,(function*(){let t="";if(n){const o=new Date;o.setTime(o.getTime()+n),t="; expires="+o.toUTCString()}let d=i;if(!d){d=(()=>{let o="";if("undefined"!=typeof window&&window.location)o=window.location.hostname;else if("undefined"!=typeof globalThis&&globalThis.location)o=globalThis.location.hostname;else if("undefined"!=typeof self&&self.location)o=self.location.hostname;else if("undefined"!=typeof document&&document.location)o=document.location.hostname;else{if("undefined"==typeof document||!document.domain)return"";o=document.domain}if(!o)return"";if("localhost"===o||/^(\d{1,3}\.){3}\d{1,3}$/.test(o))return o;const e=o.split(".");if(e.length<2)return o;const n=["com.br","net.br","org.br","gov.br","edu.br","co.uk","org.uk","ac.uk"];if(e.length>=2){const o=e.slice(-2).join(".");return n.includes(o)?2===e.length?"."+o:3===e.length?"."+e.join("."):"."+e.slice(-3).join("."):2===e.length?"."+e.join("."):"."+e.slice(-2).join(".")}return o})()||void 0}const l=d?"; domain="+d:"",c=encodeURIComponent(e||"").replace(/[^\x20-\x7E]/g,(o=>encodeURIComponent(o))),r=o+"="+c+t+"; path=/; SameSite=None; Secure"+l;(null===self||void 0===self?void 0:self.Shopify)&&(null===self||void 0===self?void 0:self.Shopify.browser)?yield self.Shopify.browser.cookie.set(r):document.cookie=r})),setAllStorage=(o,e,n)=>__awaiter(void 0,void 0,void 0,(function*(){yield((o,e)=>__awaiter(void 0,void 0,void 0,(function*(){var n;(null===(n=null===self||void 0===self?void 0:self.Shopify)||void 0===n?void 0:n.browser)?yield self.Shopify.browser.localStorage.setItem(o,e):localStorage.setItem(o,e)})))(o,e),yield setCookie(o,e,n)}));const getCompanyId=()=>{var o,e,n,i;return"undefined"!=typeof window&&(null===(o=window.__SOLOMON__)||void 0===o?void 0:o.companyId)?window.__SOLOMON__.companyId:"undefined"!=typeof self&&(null===(e=self.__SOLOMON__)||void 0===e?void 0:e.companyId)?self.__SOLOMON__.companyId:"undefined"!=typeof window&&(null===(n=window.SOLOMON)||void 0===n?void 0:n.companyId)?window.SOLOMON.companyId:"undefined"!=typeof self&&(null===(i=self.SOLOMON)||void 0===i?void 0:i.companyId)?self.SOLOMON.companyId:""},getUtmParameter=o=>{var e,n,i,t,d,l,c,r,u,a;let s=null!==(l=null===(d=null===(t=null===(i=null===(n=null===(e=null===self||void 0===self?void 0:self.Shopify)||void 0===e?void 0:e.init)||void 0===n?void 0:n.context)||void 0===i?void 0:i.document)||void 0===t?void 0:t.location)||void 0===d?void 0:d.search)&&void 0!==l?l:null===(c=null===window||void 0===window?void 0:window.location)||void 0===c?void 0:c.search;const f=null!==(u=null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hash)&&void 0!==u?u:"";let v="";f.includes("?")?v=f.substring(f.indexOf("?")):f.length>1&&f.includes("=")&&(v="?"+f.substring(1));const m=new URLSearchParams(s);if(v){new URLSearchParams(v).forEach(((o,e)=>{m.append(e,o)}))}const p=m.getAll(o);try{const e=getCompanyId();if(e&&"8WX2T4ZJz6JonRNrjhOj"===e){const e=m.get("parceiro");if(e&&"utm_source"===o)return"Influenciador";if(e&&"utm_campaign"===o)return e}}catch(o){}if(0===p.length)return"";if(["utm_campaign","sol_campaign","utm_content","sol_content"].includes(o)&&p.length>1){const o=p.filter((o=>/^\d+$/.test(o)));if(o.length>0){return Math.max(...o.map(Number)).toString()}}return null!==(a=p[0])&&void 0!==a?a:""};var session_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const n="solomon-session-id";const getSessionId=()=>session_awaiter(void 0,void 0,void 0,(function*(){const o=(yield getCookie(n))||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)}));return yield setCookie(n,o,18e5),o}));var user_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const i="solomon-user-id";const getUserId=()=>user_awaiter(void 0,void 0,void 0,(function*(){const o=(yield getAllStorage(i))||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)}));return yield setAllStorage(i,o,31536e6),o}));var fbp_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const getFbp=()=>fbp_awaiter(void 0,void 0,void 0,(function*(){return yield getCookie("_fbp")})),getFbc=()=>fbp_awaiter(void 0,void 0,void 0,(function*(){return yield getCookie("_fbc")}));var legacy_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};var t,events_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};!function(o){o.VIEW_PAGE="VIEW_PAGE",o.CONTENT_VIEW="CONTENT_VIEW",o.ADD_TO_CART="ADD_TO_CART",o.INITIATE_CHECKOUT="INITIATE_CHECKOUT",o.ADD_SHIPPING_INFO="ADD_SHIPPING_INFO",o.ADD_CUSTOMER_INFO="ADD_CUSTOMER_INFO",o.ADD_PAYMENT_INFO="ADD_PAYMENT_INFO",o.CHECKOUT_COMPLETED="CHECKOUT_COMPLETED"}(t||(t={}));const getUniqueId=()=>events_awaiter(void 0,void 0,void 0,(function*(){const o="uniqueId",e="uniqueId",n=getUtmParameter("utm_term");let i;const t=/^[a-z0-9]{9}_([0-9]+)$/,d="undefined"!=typeof window&&window.location?window.location.hostname:"undefined"!=typeof self&&(null===(u=null===(r=null===(c=null===(l=null===self||void 0===self?void 0:self.Shopify)||void 0===l?void 0:l.init)||void 0===c?void 0:c.context)||void 0===r?void 0:r.document)||void 0===u?void 0:u.location)?self.Shopify.init.context.document.location.hostname:"";var l,c,r,u;const a=(()=>{var o,e,n,i;return"undefined"!=typeof document&&document.referrer?document.referrer:"undefined"!=typeof self&&(null===(i=null===(n=null===(e=null===(o=null===self||void 0===self?void 0:self.Shopify)||void 0===o?void 0:o.init)||void 0===e?void 0:e.context)||void 0===n?void 0:n.document)||void 0===i?void 0:i.referrer)?self.Shopify.init.context.document.referrer:""})(),s=yield getLocalStorage(o);if(s)i=s;else{const l=yield getCookie(e);l?(i=l,yield setAllStorage(o,i,31536e6)):n&&t.test(n)&&-1!==a.indexOf(d)?(i=n,yield setAllStorage(o,i,31536e6)):(i=Math.random().toString(36).substr(2,9)+"_"+(new Date).getTime(),yield setAllStorage(o,i,31536e6))}return s&&(yield setCookie(e,i,31536e6)),i})),SolomonEvent=(o,e,n,i)=>events_awaiter(void 0,void 0,void 0,(function*(){var t,d,l,c,r,u,a,s,f,v,m,p,y,w,_,h,g,x,O,S,b,I,T;return{company_id:o,event_id:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)})),event_time:(new Date).toISOString(),session_id:yield getSessionId(),user_id:yield getUserId(),fbp:yield getFbp(),fbc:yield getFbc(),legacy_id:yield legacy_awaiter(void 0,void 0,void 0,(function*(){return(yield getAllStorage("uniqueId"))||null})),custom_aliases:yield i,event_type:String(e),page_referrer:null!==(r=null===(c=null===(l=null===(d=null===(t=null===self||void 0===self?void 0:self.Shopify)||void 0===t?void 0:t.init)||void 0===d?void 0:d.context)||void 0===l?void 0:l.document)||void 0===c?void 0:c.referrer)&&void 0!==r?r:null===document||void 0===document?void 0:document.referrer,page_path:null!==(y=null!==(m=null===(v=null===(f=null===(s=null===(a=null===(u=null===self||void 0===self?void 0:self.Shopify)||void 0===u?void 0:u.init)||void 0===a?void 0:a.context)||void 0===s?void 0:s.document)||void 0===f?void 0:f.location)||void 0===v?void 0:v.pathname)&&void 0!==m?m:null===(p=null===window||void 0===window?void 0:window.location)||void 0===p?void 0:p.pathname)&&void 0!==y?y:"",utm_source:null!==(w=getUtmParameter("utm_source"))&&void 0!==w?w:"",utm_medium:null!==(_=getUtmParameter("utm_medium"))&&void 0!==_?_:"",utm_campaign:null!==(h=getUtmParameter("utm_campaign"))&&void 0!==h?h:"",utm_term:null!==(g=getUtmParameter("utm_term"))&&void 0!==g?g:"",utm_content:null!==(x=getUtmParameter("utm_content"))&&void 0!==x?x:"",sol_source:null!==(O=getUtmParameter("sol_source"))&&void 0!==O?O:"",sol_medium:null!==(S=getUtmParameter("sol_medium"))&&void 0!==S?S:"",sol_campaign:null!==(b=getUtmParameter("sol_campaign"))&&void 0!==b?b:"",sol_content:null!==(I=getUtmParameter("sol_content"))&&void 0!==I?I:"",event_payload:n,voxus_url:null!==(T=localStorage.getItem("analytics:session"))&&void 0!==T?T:""}})),TouchpointEvent=(o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){var i,t,d,l,c,r,u,a,s,f,v,m,p,y,w,_,h,g,x,O,S,b,I,T,N,E,j,D,P,C,k,A;let M="true"===new URLSearchParams(window.location.search).get("vendedor");if((document.referrer.includes("desk.hyperflow.global")||document.referrer.includes("app.yampi.com")||document.referrer.includes("app.reportana.com"))&&(M=!0),M)return setCookie("is_seller","true",365),void localStorage.setItem("is_seller","true");if("true"===(yield getCookie("is_seller"))||M||"true"===localStorage.getItem("is_seller"))return;const U=(yield getFbp())||(yield getCookie("_fbp"))||"",L=(yield getFbc())||(yield getCookie("_fbc"))||"",R=getUtmParameter("fbclid")||(yield getCookie("_fbclid"))||"",K=(yield getCookie("_ga"))||"",H="undefined"!=typeof navigator?navigator.language.replace("-","_"):"",V=null!==(i=getUtmParameter("utm_term"))&&void 0!==i?i:"",F=null!==(s=null!==(u=null===(r=null===(c=null===(l=null===(d=null===(t=null===self||void 0===self?void 0:self.Shopify)||void 0===t?void 0:t.init)||void 0===d?void 0:d.context)||void 0===l?void 0:l.document)||void 0===c?void 0:c.location)||void 0===r?void 0:r.search)&&void 0!==u?u:null===(a=null===window||void 0===window?void 0:window.location)||void 0===a?void 0:a.search)&&void 0!==s?s:"";let W="";try{if("undefined"!=typeof navigator){const o=/.*\s(.+)/.exec((new Date).toLocaleDateString(navigator.language,{timeZoneName:"short"}));W=o?o[1]:""}}catch(o){W=""}let G="",z=yield e;G="shoppub"===n?(null==z?void 0:z.customer_id)||"":"shopify"===n||"nuvemshop"===n||"tray"===n||"vtex"===n||"trinio"===n||"magento"===n||"buda"===n||"linx"===n?(null==z?void 0:z.cart_token)||"":"magazord"===n?(null==z?void 0:z.email)||"":"yampi"===n||"woocommerce"===n?(null==z?void 0:z.transaction_id)||(null==z?void 0:z.cart_token)||"":"uappi"===n||"bagy"===n||"wake"===n||"wbuy"===n?(null==z?void 0:z.order_id)||"":"cartpanda"===n?(null==z?void 0:z.cart_token)||"":"b4you"===n?(null==z?void 0:z.cart_token)||(null==z?void 0:z.customer_id)||"":"loja_integrada"===n?(null==z?void 0:z.transaction_id)||"":"custom"===n?(null==z?void 0:z.user_id)||"":(null==z?void 0:z.cart_token)||(null==z?void 0:z.customer_id)||(null==z?void 0:z.email)||"";let J=!1;try{const o=performance.getEntriesByType("navigation")[0];J="reload"===(null==o?void 0:o.type)}catch(o){J=1===(null===(f=null===performance||void 0===performance?void 0:performance.navigation)||void 0===f?void 0:f.type)}let q=null!==(w=null===(y=null===(p=null===(m=null===(v=null===self||void 0===self?void 0:self.Shopify)||void 0===v?void 0:v.init)||void 0===m?void 0:m.context)||void 0===p?void 0:p.document)||void 0===y?void 0:y.referrer)&&void 0!==w?w:null===document||void 0===document?void 0:document.referrer;((null===window||void 0===window?void 0:window.pageViewFired)||J)&&(q=""),window.pageViewFired=!0;var Y={id:yield getUniqueId(),referrer:q,path:null!==(I=null!==(S=null===(O=null===(x=null===(g=null===(h=null===(_=null===self||void 0===self?void 0:self.Shopify)||void 0===_?void 0:_.init)||void 0===h?void 0:h.context)||void 0===g?void 0:g.document)||void 0===x?void 0:x.location)||void 0===O?void 0:O.pathname)&&void 0!==S?S:null===(b=null===window||void 0===window?void 0:window.location)||void 0===b?void 0:b.pathname)&&void 0!==I?I:"",utm_source:null!==(T=getUtmParameter("utm_source"))&&void 0!==T?T:"",utm_medium:null!==(N=getUtmParameter("utm_medium"))&&void 0!==N?N:"",utm_campaign:null!==(E=getUtmParameter("utm_campaign"))&&void 0!==E?E:"",utm_term:yield getUniqueId(),utm_content:null!==(j=getUtmParameter("utm_content"))&&void 0!==j?j:"",sol_source:null!==(D=getUtmParameter("sol_source"))&&void 0!==D?D:"",sol_medium:null!==(P=getUtmParameter("sol_medium"))&&void 0!==P?P:"",sol_campaign:null!==(C=getUtmParameter("sol_campaign"))&&void 0!==C?C:"",sol_content:null!==(k=getUtmParameter("sol_content"))&&void 0!==k?k:"",fbp:U,fbc:L,ga_id:K,fbclid:R,locale:H?H.charAt(0).toUpperCase()+H.slice(1):"",timezone:W,osVersion:"undefined"!=typeof navigator?navigator.appVersion.split(" ")[0]:"",screenWidth:"undefined"!=typeof screen?screen.width:0,screenHeight:"undefined"!=typeof screen?screen.height:0,density:"undefined"!=typeof window?window.devicePixelRatio:1,cpuCores:"undefined"!=typeof navigator?navigator.hardwareConcurrency:0,queryParams:F,debug:"",old_id:V,shopify_id:o,current_domain:"undefined"!=typeof window?window.location.hostname:"",cart_token:G,email:null===(A=yield e)||void 0===A?void 0:A.email};return yield(o=>events_awaiter(void 0,void 0,void 0,(function*(){const e=["utm_source","utm_medium","utm_campaign","utm_content","sol_source","sol_medium","sol_campaign","sol_content"],n={},i=yield getCookie("utmsTrack");i&&i.split("&").forEach((o=>{const e=o.split("=");2===e.length&&(n[e[0]]=e[1])}));const t={utm_source:o.utm_source,utm_medium:o.utm_medium,utm_campaign:o.utm_campaign,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};let d=!1;for(const o of e)if(t[o]){d=!0;break}let l=!1;const c=o.referrer||"",r=o.current_domain||"";if(c&&r)try{const o=new URL(c),e=(o=>{const e=o.split(".");if(e.length<=2)return o;const n=e.slice(-2).join(".");return["com.br","net.br","org.br","gov.br","edu.br","co.uk","co.jp","co.kr","co.za","co.in","com.au","com.mx","com.ar","com.co"].includes(n)?e.slice(-3).join("."):e.slice(-2).join(".")})(r),n=["mercadopago.com","myshopify.com"],i=o.hostname.includes(e),t=n.some((e=>o.hostname.includes(e)));l=!i&&!t}catch(o){l=!1}let u={};if((d||l)&&"Sz8mKHeQqQcPpUnSyET0"!=getCompanyId()){u.utm_term=o.utm_term;for(const o of e)t[o]&&(u[o]=t[o])}else{for(const o in n)n.hasOwnProperty(o)&&(u[o]=n[o]);o.utm_term&&(u.utm_term=o.utm_term);for(const o of e)t[o]&&(u[o]=t[o])}const a=[];for(const o in u)u.hasOwnProperty(o)&&a.push(o+"="+u[o]);yield setCookie("utmsTrack",a.join("&"),2592e6),yield setCookie("track_utms",a.join("&"),2592e6),yield setCookie("yeverUtmsTrack",a.join("&"),2592e6)})))(Y),Y.utmsTrack=yield getCookie("utmsTrack"),Y})),EventTouchpoint=(o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield TouchpointEvent(n||("undefined"!=typeof window&&(null===(i=window.__SOLOMON__)||void 0===i?void 0:i.accountId)?window.__SOLOMON__.accountId:"undefined"!=typeof self&&(null===(t=self.__SOLOMON__)||void 0===t?void 0:t.accountId)?self.__SOLOMON__.accountId:"undefined"!=typeof window&&(null===(d=window.SOLOMON)||void 0===d?void 0:d.accountId)?window.SOLOMON.accountId:"undefined"!=typeof self&&(null===(l=self.SOLOMON)||void 0===l?void 0:l.accountId)?self.SOLOMON.accountId:""),o,e);var i,t,d,l}));var publish_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};var client_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};class SolomonSDK{constructor(o){this.config=o,this.config.debug&&console.log("[SolomonSDK] initialized",o)}track(o,e,n){return client_awaiter(this,void 0,void 0,(function*(){this.config.debug&&console.log("[SolomonSDK] Tracking event:",o,e);const i=n?Promise.resolve(n):void 0;try{let n;switch(o){case"VIEW_PAGE":{const o="undefined"!=typeof window?window.location.href:"";n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.VIEW_PAGE,o,e)})))({url:o,path:"undefined"!=typeof window?window.location.pathname:void 0},i,this.config.companyId);break}case"CONTENT_VIEW":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.CONTENT_VIEW,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_TO_CART":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_TO_CART,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"INITIATE_CHECKOUT":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.INITIATE_CHECKOUT,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_SHIPPING_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_SHIPPING_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_CUSTOMER_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_CUSTOMER_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_PAYMENT_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_PAYMENT_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"CHECKOUT_COMPLETED":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.CHECKOUT_COMPLETED,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;default:n=SolomonEvent(this.config.companyId,o,Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i)}if(this.config.useTouchpoint){const o=EventTouchpoint(i,"custom",this.config.companyId);yield(d=o,publish_awaiter(void 0,void 0,void 0,(function*(){var o;const e=yield d,n=(null===(o=window.__SOLOMON__)||void 0===o?void 0:o.pixelUrl)?window.__SOLOMON__.pixelUrl+"/event":"https://pixel.solomon.com.br/event";try{const o=yield fetch(n,{method:"POST",mode:"cors",credentials:"omit",headers:{"content-type":"application/json"},body:JSON.stringify(e)});if(o.ok){const e=yield o.text();e&&JSON.parse(e)}else console.error("Erro HTTP ao enviar evento:",o.status,o.statusText)}catch(o){console.error("Erro ao enviar evento:",o)}})))}yield(o=>publish_awaiter(void 0,void 0,void 0,(function*(){var e;const n=yield o,i=(null===(e=window.__SOLOMON__)||void 0===e?void 0:e.webanalyticsUrl)?window.__SOLOMON__.webanalyticsUrl+"/event?mode=web":"https://webanalytics.solomon.com.br/event?mode=web";try{const o=yield fetch(i,{method:"POST",mode:"cors",credentials:"omit",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(o.ok){const e=yield o.text();e&&JSON.parse(e)}else{console.error("[Solomon] Erro HTTP ao enviar evento:",o.status,o.statusText);const e=yield o.text().catch((()=>"Unable to read error response"));console.error("[Solomon] Response error details:",e)}}catch(o){console.error("Erro ao enviar evento:",o)}})))(n),this.config.debug&&console.log("[SolomonSDK] Event tracked successfully:",o)}catch(o){throw console.error("[SolomonSDK] Error tracking event:",o),o}var d}))}}var d=e.C,l=e.A;export{d as SolomonSDK,l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(o,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SolomonSDK=e():o.SolomonSDK=e()}(this,(()=>(()=>{"use strict";var o={d:(e,n)=>{for(var i in n)o.o(n,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(o,e)=>Object.prototype.hasOwnProperty.call(o,e),r:o=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})}},e={};o.r(e),o.d(e,{SolomonSDK:()=>SolomonSDK,default:()=>SolomonSDK});var __awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const getCookie=o=>__awaiter(void 0,void 0,void 0,(function*(){if((null===self||void 0===self?void 0:self.Shopify)&&(null===self||void 0===self?void 0:self.Shopify.browser)){const e=yield self.Shopify.browser.cookie.get(o);return e?decodeURIComponent(e):null}{if(!document.cookie||""===document.cookie)return null;const e=document.cookie.split(";");for(let n=0;n<e.length;n++){const i=e[n].trim();if(i.substring(0,o.length+1)===o+"=")return decodeURIComponent(i.substring(o.length+1))}return null}})),getLocalStorage=o=>__awaiter(void 0,void 0,void 0,(function*(){var e;return(null===(e=null===self||void 0===self?void 0:self.Shopify)||void 0===e?void 0:e.browser)?yield self.Shopify.browser.localStorage.getItem(o):localStorage.getItem(o)})),getAllStorage=o=>__awaiter(void 0,void 0,void 0,(function*(){return(yield getLocalStorage(o))||(yield getCookie(o))})),setCookie=(o,e,n,i)=>__awaiter(void 0,void 0,void 0,(function*(){let t="";if(n){const o=new Date;o.setTime(o.getTime()+n),t="; expires="+o.toUTCString()}let d=i;if(!d){d=(()=>{let o="";if("undefined"!=typeof window&&window.location)o=window.location.hostname;else if("undefined"!=typeof globalThis&&globalThis.location)o=globalThis.location.hostname;else if("undefined"!=typeof self&&self.location)o=self.location.hostname;else if("undefined"!=typeof document&&document.location)o=document.location.hostname;else{if("undefined"==typeof document||!document.domain)return"";o=document.domain}if(!o)return"";if("localhost"===o||/^(\d{1,3}\.){3}\d{1,3}$/.test(o))return o;const e=o.split(".");if(e.length<2)return o;const n=["com.br","net.br","org.br","gov.br","edu.br","co.uk","org.uk","ac.uk"];if(e.length>=2){const o=e.slice(-2).join(".");return n.includes(o)?2===e.length?"."+o:3===e.length?"."+e.join("."):"."+e.slice(-3).join("."):2===e.length?"."+e.join("."):"."+e.slice(-2).join(".")}return o})()||void 0}const l=d?"; domain="+d:"",c=encodeURIComponent(e||"").replace(/[^\x20-\x7E]/g,(o=>encodeURIComponent(o))),r=o+"="+c+t+"; path=/; SameSite=None; Secure"+l;(null===self||void 0===self?void 0:self.Shopify)&&(null===self||void 0===self?void 0:self.Shopify.browser)?yield self.Shopify.browser.cookie.set(r):document.cookie=r})),setAllStorage=(o,e,n)=>__awaiter(void 0,void 0,void 0,(function*(){yield((o,e)=>__awaiter(void 0,void 0,void 0,(function*(){var n;(null===(n=null===self||void 0===self?void 0:self.Shopify)||void 0===n?void 0:n.browser)?yield self.Shopify.browser.localStorage.setItem(o,e):localStorage.setItem(o,e)})))(o,e),yield setCookie(o,e,n)}));const getCompanyId=()=>{var o,e,n,i;return"undefined"!=typeof window&&(null===(o=window.__SOLOMON__)||void 0===o?void 0:o.companyId)?window.__SOLOMON__.companyId:"undefined"!=typeof self&&(null===(e=self.__SOLOMON__)||void 0===e?void 0:e.companyId)?self.__SOLOMON__.companyId:"undefined"!=typeof window&&(null===(n=window.SOLOMON)||void 0===n?void 0:n.companyId)?window.SOLOMON.companyId:"undefined"!=typeof self&&(null===(i=self.SOLOMON)||void 0===i?void 0:i.companyId)?self.SOLOMON.companyId:""},getUtmParameter=o=>{var e,n,i,t,d,l,c,r,u,a;let s=null!==(l=null===(d=null===(t=null===(i=null===(n=null===(e=null===self||void 0===self?void 0:self.Shopify)||void 0===e?void 0:e.init)||void 0===n?void 0:n.context)||void 0===i?void 0:i.document)||void 0===t?void 0:t.location)||void 0===d?void 0:d.search)&&void 0!==l?l:null===(c=null===window||void 0===window?void 0:window.location)||void 0===c?void 0:c.search;const f=null!==(u=null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hash)&&void 0!==u?u:"";let v="";f.includes("?")?v=f.substring(f.indexOf("?")):f.length>1&&f.includes("=")&&(v="?"+f.substring(1));const m=new URLSearchParams(s);if(v){new URLSearchParams(v).forEach(((o,e)=>{m.append(e,o)}))}const p=m.getAll(o);try{const e=getCompanyId();if(e&&"8WX2T4ZJz6JonRNrjhOj"===e){const e=m.get("parceiro");if(e&&"utm_source"===o)return"Influenciador";if(e&&"utm_campaign"===o)return e}}catch(o){}if(0===p.length)return"";if(["utm_campaign","sol_campaign","utm_content","sol_content"].includes(o)&&p.length>1){const o=p.filter((o=>/^\d+$/.test(o)));if(o.length>0){return Math.max(...o.map(Number)).toString()}}return null!==(a=p[0])&&void 0!==a?a:""};var session_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const n="solomon-session-id";const getSessionId=()=>session_awaiter(void 0,void 0,void 0,(function*(){const o=(yield getCookie(n))||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)}));return yield setCookie(n,o,18e5),o}));var user_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const i="solomon-user-id";const getUserId=()=>user_awaiter(void 0,void 0,void 0,(function*(){const o=(yield getAllStorage(i))||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)}));return yield setAllStorage(i,o,31536e6),o}));var fbp_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};const getFbp=()=>fbp_awaiter(void 0,void 0,void 0,(function*(){return yield getCookie("_fbp")})),getFbc=()=>fbp_awaiter(void 0,void 0,void 0,(function*(){return yield getCookie("_fbc")}));var legacy_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};var t,events_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};!function(o){o.VIEW_PAGE="VIEW_PAGE",o.CONTENT_VIEW="CONTENT_VIEW",o.ADD_TO_CART="ADD_TO_CART",o.INITIATE_CHECKOUT="INITIATE_CHECKOUT",o.ADD_SHIPPING_INFO="ADD_SHIPPING_INFO",o.ADD_CUSTOMER_INFO="ADD_CUSTOMER_INFO",o.ADD_PAYMENT_INFO="ADD_PAYMENT_INFO",o.CHECKOUT_COMPLETED="CHECKOUT_COMPLETED"}(t||(t={}));const getUniqueId=()=>events_awaiter(void 0,void 0,void 0,(function*(){const o="uniqueId",e="uniqueId",n=getUtmParameter("utm_term");let i;const t=/^[a-z0-9]{9}_([0-9]+)$/,d="undefined"!=typeof window&&window.location?window.location.hostname:"undefined"!=typeof self&&(null===(u=null===(r=null===(c=null===(l=null===self||void 0===self?void 0:self.Shopify)||void 0===l?void 0:l.init)||void 0===c?void 0:c.context)||void 0===r?void 0:r.document)||void 0===u?void 0:u.location)?self.Shopify.init.context.document.location.hostname:"";var l,c,r,u;const a=(()=>{var o,e,n,i;return"undefined"!=typeof document&&document.referrer?document.referrer:"undefined"!=typeof self&&(null===(i=null===(n=null===(e=null===(o=null===self||void 0===self?void 0:self.Shopify)||void 0===o?void 0:o.init)||void 0===e?void 0:e.context)||void 0===n?void 0:n.document)||void 0===i?void 0:i.referrer)?self.Shopify.init.context.document.referrer:""})(),s=yield getLocalStorage(o);if(s)i=s;else{const l=yield getCookie(e);l?(i=l,yield setAllStorage(o,i,31536e6)):n&&t.test(n)&&-1!==a.indexOf(d)?(i=n,yield setAllStorage(o,i,31536e6)):(i=Math.random().toString(36).substr(2,9)+"_"+(new Date).getTime(),yield setAllStorage(o,i,31536e6))}return s&&(yield setCookie(e,i,31536e6)),i})),SolomonEvent=(o,e,n,i)=>events_awaiter(void 0,void 0,void 0,(function*(){var t,d,l,c,r,u,a,s,f,v,m,p,y,w,_,h,g,x,O,S,b,I,T;return{company_id:o,event_id:"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(o=>{const e=15&crypto.getRandomValues(new Uint8Array(1))[0];return("x"===o?e:3&e|8).toString(16)})),event_time:(new Date).toISOString(),session_id:yield getSessionId(),user_id:yield getUserId(),fbp:yield getFbp(),fbc:yield getFbc(),legacy_id:yield legacy_awaiter(void 0,void 0,void 0,(function*(){return(yield getAllStorage("uniqueId"))||null})),custom_aliases:yield i,event_type:String(e),page_referrer:null!==(r=null===(c=null===(l=null===(d=null===(t=null===self||void 0===self?void 0:self.Shopify)||void 0===t?void 0:t.init)||void 0===d?void 0:d.context)||void 0===l?void 0:l.document)||void 0===c?void 0:c.referrer)&&void 0!==r?r:null===document||void 0===document?void 0:document.referrer,page_path:null!==(y=null!==(m=null===(v=null===(f=null===(s=null===(a=null===(u=null===self||void 0===self?void 0:self.Shopify)||void 0===u?void 0:u.init)||void 0===a?void 0:a.context)||void 0===s?void 0:s.document)||void 0===f?void 0:f.location)||void 0===v?void 0:v.pathname)&&void 0!==m?m:null===(p=null===window||void 0===window?void 0:window.location)||void 0===p?void 0:p.pathname)&&void 0!==y?y:"",utm_source:null!==(w=getUtmParameter("utm_source"))&&void 0!==w?w:"",utm_medium:null!==(_=getUtmParameter("utm_medium"))&&void 0!==_?_:"",utm_campaign:null!==(h=getUtmParameter("utm_campaign"))&&void 0!==h?h:"",utm_term:null!==(g=getUtmParameter("utm_term"))&&void 0!==g?g:"",utm_content:null!==(x=getUtmParameter("utm_content"))&&void 0!==x?x:"",sol_source:null!==(O=getUtmParameter("sol_source"))&&void 0!==O?O:"",sol_medium:null!==(S=getUtmParameter("sol_medium"))&&void 0!==S?S:"",sol_campaign:null!==(b=getUtmParameter("sol_campaign"))&&void 0!==b?b:"",sol_content:null!==(I=getUtmParameter("sol_content"))&&void 0!==I?I:"",event_payload:n,voxus_url:null!==(T=localStorage.getItem("analytics:session"))&&void 0!==T?T:""}})),TouchpointEvent=(o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){var i,t,d,l,c,r,u,a,s,f,v,m,p,y,w,_,h,g,x,O,S,b,I,T,N,j,E,D,P,k,C,A;let M="true"===new URLSearchParams(window.location.search).get("vendedor");if((document.referrer.includes("desk.hyperflow.global")||document.referrer.includes("app.yampi.com")||document.referrer.includes("app.reportana.com"))&&(M=!0),M)return setCookie("is_seller","true",365),void localStorage.setItem("is_seller","true");if("true"===(yield getCookie("is_seller"))||M||"true"===localStorage.getItem("is_seller"))return;const U=(yield getFbp())||(yield getCookie("_fbp"))||"",L=(yield getFbc())||(yield getCookie("_fbc"))||"",R=getUtmParameter("fbclid")||(yield getCookie("_fbclid"))||"",K=(yield getCookie("_ga"))||"",H="undefined"!=typeof navigator?navigator.language.replace("-","_"):"",V=null!==(i=getUtmParameter("utm_term"))&&void 0!==i?i:"",F=null!==(s=null!==(u=null===(r=null===(c=null===(l=null===(d=null===(t=null===self||void 0===self?void 0:self.Shopify)||void 0===t?void 0:t.init)||void 0===d?void 0:d.context)||void 0===l?void 0:l.document)||void 0===c?void 0:c.location)||void 0===r?void 0:r.search)&&void 0!==u?u:null===(a=null===window||void 0===window?void 0:window.location)||void 0===a?void 0:a.search)&&void 0!==s?s:"";let W="";try{if("undefined"!=typeof navigator){const o=/.*\s(.+)/.exec((new Date).toLocaleDateString(navigator.language,{timeZoneName:"short"}));W=o?o[1]:""}}catch(o){W=""}let G="",z=yield e;G="shoppub"===n?(null==z?void 0:z.customer_id)||"":"shopify"===n||"nuvemshop"===n||"tray"===n||"vtex"===n||"trinio"===n||"magento"===n||"buda"===n||"linx"===n?(null==z?void 0:z.cart_token)||"":"magazord"===n?(null==z?void 0:z.email)||"":"yampi"===n||"woocommerce"===n?(null==z?void 0:z.transaction_id)||(null==z?void 0:z.cart_token)||"":"uappi"===n||"bagy"===n||"wake"===n||"wbuy"===n?(null==z?void 0:z.order_id)||"":"cartpanda"===n?(null==z?void 0:z.cart_token)||"":"b4you"===n?(null==z?void 0:z.cart_token)||(null==z?void 0:z.customer_id)||"":"loja_integrada"===n?(null==z?void 0:z.transaction_id)||"":"custom"===n?(null==z?void 0:z.user_id)||"":(null==z?void 0:z.cart_token)||(null==z?void 0:z.customer_id)||(null==z?void 0:z.email)||"";let J=!1;try{const o=performance.getEntriesByType("navigation")[0];J="reload"===(null==o?void 0:o.type)}catch(o){J=1===(null===(f=null===performance||void 0===performance?void 0:performance.navigation)||void 0===f?void 0:f.type)}let q=null!==(w=null===(y=null===(p=null===(m=null===(v=null===self||void 0===self?void 0:self.Shopify)||void 0===v?void 0:v.init)||void 0===m?void 0:m.context)||void 0===p?void 0:p.document)||void 0===y?void 0:y.referrer)&&void 0!==w?w:null===document||void 0===document?void 0:document.referrer;((null===window||void 0===window?void 0:window.pageViewFired)||J)&&(q=""),window.pageViewFired=!0;var Y={id:yield getUniqueId(),referrer:q,path:null!==(I=null!==(S=null===(O=null===(x=null===(g=null===(h=null===(_=null===self||void 0===self?void 0:self.Shopify)||void 0===_?void 0:_.init)||void 0===h?void 0:h.context)||void 0===g?void 0:g.document)||void 0===x?void 0:x.location)||void 0===O?void 0:O.pathname)&&void 0!==S?S:null===(b=null===window||void 0===window?void 0:window.location)||void 0===b?void 0:b.pathname)&&void 0!==I?I:"",utm_source:null!==(T=getUtmParameter("utm_source"))&&void 0!==T?T:"",utm_medium:null!==(N=getUtmParameter("utm_medium"))&&void 0!==N?N:"",utm_campaign:null!==(j=getUtmParameter("utm_campaign"))&&void 0!==j?j:"",utm_term:yield getUniqueId(),utm_content:null!==(E=getUtmParameter("utm_content"))&&void 0!==E?E:"",sol_source:null!==(D=getUtmParameter("sol_source"))&&void 0!==D?D:"",sol_medium:null!==(P=getUtmParameter("sol_medium"))&&void 0!==P?P:"",sol_campaign:null!==(k=getUtmParameter("sol_campaign"))&&void 0!==k?k:"",sol_content:null!==(C=getUtmParameter("sol_content"))&&void 0!==C?C:"",fbp:U,fbc:L,ga_id:K,fbclid:R,locale:H?H.charAt(0).toUpperCase()+H.slice(1):"",timezone:W,osVersion:"undefined"!=typeof navigator?navigator.appVersion.split(" ")[0]:"",screenWidth:"undefined"!=typeof screen?screen.width:0,screenHeight:"undefined"!=typeof screen?screen.height:0,density:"undefined"!=typeof window?window.devicePixelRatio:1,cpuCores:"undefined"!=typeof navigator?navigator.hardwareConcurrency:0,queryParams:F,debug:"",old_id:V,shopify_id:o,current_domain:"undefined"!=typeof window?window.location.hostname:"",cart_token:G,email:null===(A=yield e)||void 0===A?void 0:A.email};return yield(o=>events_awaiter(void 0,void 0,void 0,(function*(){const e=["utm_source","utm_medium","utm_campaign","utm_content","sol_source","sol_medium","sol_campaign","sol_content"],n={},i=yield getCookie("utmsTrack");i&&i.split("&").forEach((o=>{const e=o.split("=");2===e.length&&(n[e[0]]=e[1])}));const t={utm_source:o.utm_source,utm_medium:o.utm_medium,utm_campaign:o.utm_campaign,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};let d=!1;for(const o of e)if(t[o]){d=!0;break}let l=!1;const c=o.referrer||"",r=o.current_domain||"";if(c&&r)try{const o=new URL(c),e=(o=>{const e=o.split(".");if(e.length<=2)return o;const n=e.slice(-2).join(".");return["com.br","net.br","org.br","gov.br","edu.br","co.uk","co.jp","co.kr","co.za","co.in","com.au","com.mx","com.ar","com.co"].includes(n)?e.slice(-3).join("."):e.slice(-2).join(".")})(r),n=["mercadopago.com","myshopify.com"],i=o.hostname.includes(e),t=n.some((e=>o.hostname.includes(e)));l=!i&&!t}catch(o){l=!1}let u={};if((d||l)&&"Sz8mKHeQqQcPpUnSyET0"!=getCompanyId()){u.utm_term=o.utm_term;for(const o of e)t[o]&&(u[o]=t[o])}else{for(const o in n)n.hasOwnProperty(o)&&(u[o]=n[o]);o.utm_term&&(u.utm_term=o.utm_term);for(const o of e)t[o]&&(u[o]=t[o])}const a=[];for(const o in u)u.hasOwnProperty(o)&&a.push(o+"="+u[o]);yield setCookie("utmsTrack",a.join("&"),2592e6),yield setCookie("track_utms",a.join("&"),2592e6),yield setCookie("yeverUtmsTrack",a.join("&"),2592e6)})))(Y),Y.utmsTrack=yield getCookie("utmsTrack"),Y})),EventTouchpoint=(o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield TouchpointEvent(n||("undefined"!=typeof window&&(null===(i=window.__SOLOMON__)||void 0===i?void 0:i.accountId)?window.__SOLOMON__.accountId:"undefined"!=typeof self&&(null===(t=self.__SOLOMON__)||void 0===t?void 0:t.accountId)?self.__SOLOMON__.accountId:"undefined"!=typeof window&&(null===(d=window.SOLOMON)||void 0===d?void 0:d.accountId)?window.SOLOMON.accountId:"undefined"!=typeof self&&(null===(l=self.SOLOMON)||void 0===l?void 0:l.accountId)?self.SOLOMON.accountId:""),o,e);var i,t,d,l}));var publish_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};var client_awaiter=function(o,e,n,i){return new(n||(n=Promise))((function(t,d){function fulfilled(o){try{step(i.next(o))}catch(o){d(o)}}function rejected(o){try{step(i.throw(o))}catch(o){d(o)}}function step(o){var e;o.done?t(o.value):(e=o.value,e instanceof n?e:new n((function(o){o(e)}))).then(fulfilled,rejected)}step((i=i.apply(o,e||[])).next())}))};class SolomonSDK{constructor(o){this.config=o,this.config.debug&&console.log("[SolomonSDK] initialized",o)}track(o,e,n){return client_awaiter(this,void 0,void 0,(function*(){this.config.debug&&console.log("[SolomonSDK] Tracking event:",o,e);const i=n?Promise.resolve(n):void 0;try{let n;switch(o){case"VIEW_PAGE":{const o="undefined"!=typeof window?window.location.href:"";n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.VIEW_PAGE,o,e)})))({url:o,path:"undefined"!=typeof window?window.location.pathname:void 0},i,this.config.companyId);break}case"CONTENT_VIEW":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.CONTENT_VIEW,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_TO_CART":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_TO_CART,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"INITIATE_CHECKOUT":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.INITIATE_CHECKOUT,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_SHIPPING_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_SHIPPING_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_CUSTOMER_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_CUSTOMER_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"ADD_PAYMENT_INFO":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.ADD_PAYMENT_INFO,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;case"CHECKOUT_COMPLETED":n=((o,e,n)=>events_awaiter(void 0,void 0,void 0,(function*(){return yield SolomonEvent(n||getCompanyId(),t.CHECKOUT_COMPLETED,o,e)})))(Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i,this.config.companyId);break;default:n=SolomonEvent(this.config.companyId,o,Object.assign(Object.assign({},e),{url:"undefined"!=typeof window?window.location.href:void 0,path:"undefined"!=typeof window?window.location.pathname:void 0}),i)}if(this.config.useTouchpoint){const o=EventTouchpoint(i,"custom",this.config.companyId);yield(d=o,publish_awaiter(void 0,void 0,void 0,(function*(){var o;const e=yield d,n=(null===(o=window.__SOLOMON__)||void 0===o?void 0:o.pixelUrl)?window.__SOLOMON__.pixelUrl+"/event":"https://pixel.solomon.com.br/event";try{const o=yield fetch(n,{method:"POST",mode:"cors",credentials:"omit",headers:{"content-type":"application/json"},body:JSON.stringify(e)});if(o.ok){const e=yield o.text();e&&JSON.parse(e)}else console.error("Erro HTTP ao enviar evento:",o.status,o.statusText)}catch(o){console.error("Erro ao enviar evento:",o)}})))}yield(o=>publish_awaiter(void 0,void 0,void 0,(function*(){var e;const n=yield o,i=(null===(e=window.__SOLOMON__)||void 0===e?void 0:e.webanalyticsUrl)?window.__SOLOMON__.webanalyticsUrl+"/event?mode=web":"https://webanalytics.solomon.com.br/event?mode=web";try{const o=yield fetch(i,{method:"POST",mode:"cors",credentials:"omit",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(o.ok){const e=yield o.text();e&&JSON.parse(e)}else{console.error("[Solomon] Erro HTTP ao enviar evento:",o.status,o.statusText);const e=yield o.text().catch((()=>"Unable to read error response"));console.error("[Solomon] Response error details:",e)}}catch(o){console.error("Erro ao enviar evento:",o)}})))(n),this.config.debug&&console.log("[SolomonSDK] Event tracked successfully:",o)}catch(o){throw console.error("[SolomonSDK] Error tracking event:",o),o}var d}))}}return e})()));
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const getCookie: (name: string) => Promise<string | null>;
|
|
2
|
+
declare const getLocalStorage: (name: string) => Promise<string | null>;
|
|
3
|
+
declare const getAllStorage: (name: string) => Promise<string | null>;
|
|
4
|
+
declare const getMainDomain: () => string;
|
|
5
|
+
declare const setCookie: (name: string, value: string, duration?: number, domain?: string) => Promise<void>;
|
|
6
|
+
declare const setAllStorage: (name: string, value: string, duration?: number) => Promise<void>;
|
|
7
|
+
declare function formatPhone(phone: string): string;
|
|
8
|
+
declare const getCompanyId: () => string;
|
|
9
|
+
declare const getUtmParameter: (parameter: string) => string;
|
|
10
|
+
declare const generator: () => string;
|
|
11
|
+
export { getCookie, setCookie, generator, getMainDomain, getLocalStorage, getAllStorage, setAllStorage, formatPhone, getCompanyId, getUtmParameter };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const getCookie = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
if ((self === null || self === void 0 ? void 0 : self.Shopify) && (self === null || self === void 0 ? void 0 : self.Shopify.browser)) {
|
|
12
|
+
const cookie = yield self.Shopify.browser.cookie.get(name);
|
|
13
|
+
return cookie ? decodeURIComponent(cookie) : null;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (!document.cookie || document.cookie === '') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const cookies = document.cookie.split(';');
|
|
20
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
21
|
+
const cookie = cookies[i].trim();
|
|
22
|
+
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
23
|
+
return decodeURIComponent(cookie.substring(name.length + 1));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const getLocalStorage = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
var _a;
|
|
31
|
+
if ((_a = self === null || self === void 0 ? void 0 : self.Shopify) === null || _a === void 0 ? void 0 : _a.browser) {
|
|
32
|
+
return yield self.Shopify.browser.localStorage.getItem(name);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return localStorage.getItem(name);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const getAllStorage = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
return (yield getLocalStorage(name)) || (yield getCookie(name));
|
|
40
|
+
});
|
|
41
|
+
const getMainDomain = () => {
|
|
42
|
+
let hostname = '';
|
|
43
|
+
if (typeof window !== 'undefined' && window.location) {
|
|
44
|
+
hostname = window.location.hostname;
|
|
45
|
+
}
|
|
46
|
+
else if (typeof globalThis !== 'undefined' && globalThis.location) {
|
|
47
|
+
hostname = globalThis.location.hostname;
|
|
48
|
+
}
|
|
49
|
+
else if (typeof self !== 'undefined' && self.location) {
|
|
50
|
+
hostname = self.location.hostname;
|
|
51
|
+
}
|
|
52
|
+
else if (typeof document !== 'undefined' && document.location) {
|
|
53
|
+
hostname = document.location.hostname;
|
|
54
|
+
}
|
|
55
|
+
else if (typeof document !== 'undefined' && document.domain) {
|
|
56
|
+
hostname = document.domain;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
if (!hostname) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
if (hostname === 'localhost' || /^(\d{1,3}\.){3}\d{1,3}$/.test(hostname)) {
|
|
65
|
+
return hostname;
|
|
66
|
+
}
|
|
67
|
+
const parts = hostname.split('.');
|
|
68
|
+
if (parts.length < 2) {
|
|
69
|
+
return hostname;
|
|
70
|
+
}
|
|
71
|
+
const twoPartTlds = ['com.br', 'net.br', 'org.br', 'gov.br', 'edu.br', 'co.uk', 'org.uk', 'ac.uk'];
|
|
72
|
+
if (parts.length >= 2) {
|
|
73
|
+
const lastTwoParts = parts.slice(-2).join('.');
|
|
74
|
+
if (twoPartTlds.includes(lastTwoParts)) {
|
|
75
|
+
if (parts.length === 2) {
|
|
76
|
+
const result = '.' + lastTwoParts;
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
else if (parts.length === 3) {
|
|
80
|
+
const result = '.' + parts.join('.');
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const result = '.' + parts.slice(-3).join('.');
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (parts.length === 2) {
|
|
90
|
+
const result = '.' + parts.join('.');
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const result = '.' + parts.slice(-2).join('.');
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return hostname;
|
|
100
|
+
};
|
|
101
|
+
const setCookie = (name, value, duration, domain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
let expires = "";
|
|
103
|
+
if (duration) {
|
|
104
|
+
const date = new Date();
|
|
105
|
+
date.setTime(date.getTime() + duration);
|
|
106
|
+
expires = "; expires=" + date.toUTCString();
|
|
107
|
+
}
|
|
108
|
+
let domainToUse = domain;
|
|
109
|
+
if (!domainToUse) {
|
|
110
|
+
const mainDomain = getMainDomain();
|
|
111
|
+
domainToUse = mainDomain || undefined;
|
|
112
|
+
}
|
|
113
|
+
const domainPart = domainToUse ? "; domain=" + domainToUse : "";
|
|
114
|
+
const encodedValue = encodeURIComponent(value || "");
|
|
115
|
+
const safeValue = encodedValue.replace(/[^\x20-\x7E]/g, (char) => encodeURIComponent(char));
|
|
116
|
+
const cookie = name + "=" + safeValue + expires + "; path=/; SameSite=None; Secure" + domainPart;
|
|
117
|
+
if ((self === null || self === void 0 ? void 0 : self.Shopify) && (self === null || self === void 0 ? void 0 : self.Shopify.browser)) {
|
|
118
|
+
yield self.Shopify.browser.cookie.set(cookie);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
document.cookie = cookie;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const setLocalStorage = (name, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
if ((_a = self === null || self === void 0 ? void 0 : self.Shopify) === null || _a === void 0 ? void 0 : _a.browser) {
|
|
127
|
+
yield self.Shopify.browser.localStorage.setItem(name, value);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
localStorage.setItem(name, value);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const setAllStorage = (name, value, duration) => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
yield setLocalStorage(name, value);
|
|
135
|
+
yield setCookie(name, value, duration);
|
|
136
|
+
});
|
|
137
|
+
function formatPhone(phone) {
|
|
138
|
+
return phone.replace(/\D/g, "");
|
|
139
|
+
}
|
|
140
|
+
const isNumeric = (str) => {
|
|
141
|
+
return /^\d+$/.test(str);
|
|
142
|
+
};
|
|
143
|
+
const getCompanyId = () => {
|
|
144
|
+
var _a, _b, _c, _d;
|
|
145
|
+
if (typeof window !== "undefined" && ((_a = window.__SOLOMON__) === null || _a === void 0 ? void 0 : _a.companyId)) {
|
|
146
|
+
return window.__SOLOMON__.companyId;
|
|
147
|
+
}
|
|
148
|
+
if (typeof self !== "undefined" && ((_b = self.__SOLOMON__) === null || _b === void 0 ? void 0 : _b.companyId)) {
|
|
149
|
+
return self.__SOLOMON__.companyId;
|
|
150
|
+
}
|
|
151
|
+
if (typeof window !== "undefined" && ((_c = window.SOLOMON) === null || _c === void 0 ? void 0 : _c.companyId)) {
|
|
152
|
+
return window.SOLOMON.companyId;
|
|
153
|
+
}
|
|
154
|
+
if (typeof self !== "undefined" && ((_d = self.SOLOMON) === null || _d === void 0 ? void 0 : _d.companyId)) {
|
|
155
|
+
return self.SOLOMON.companyId;
|
|
156
|
+
}
|
|
157
|
+
return "";
|
|
158
|
+
};
|
|
159
|
+
const getUtmParameter = (parameter) => {
|
|
160
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
161
|
+
let queryString = (_f = (_e = (_d = (_c = (_b = (_a = self === null || self === void 0 ? void 0 : self.Shopify) === null || _a === void 0 ? void 0 : _a.init) === null || _b === void 0 ? void 0 : _b.context) === null || _c === void 0 ? void 0 : _c.document) === null || _d === void 0 ? void 0 : _d.location) === null || _e === void 0 ? void 0 : _e.search) !== null && _f !== void 0 ? _f : (_g = window === null || window === void 0 ? void 0 : window.location) === null || _g === void 0 ? void 0 : _g.search;
|
|
162
|
+
const hash = (_j = (_h = window === null || window === void 0 ? void 0 : window.location) === null || _h === void 0 ? void 0 : _h.hash) !== null && _j !== void 0 ? _j : '';
|
|
163
|
+
let hashParams = '';
|
|
164
|
+
if (hash.includes('?')) {
|
|
165
|
+
hashParams = hash.substring(hash.indexOf('?'));
|
|
166
|
+
}
|
|
167
|
+
else if (hash.length > 1 && hash.includes('=')) {
|
|
168
|
+
hashParams = '?' + hash.substring(1);
|
|
169
|
+
}
|
|
170
|
+
const urlParams = new URLSearchParams(queryString);
|
|
171
|
+
if (hashParams) {
|
|
172
|
+
const hashUrlParams = new URLSearchParams(hashParams);
|
|
173
|
+
hashUrlParams.forEach((value, key) => {
|
|
174
|
+
urlParams.append(key, value);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const values = urlParams.getAll(parameter);
|
|
178
|
+
try {
|
|
179
|
+
const company_id = getCompanyId();
|
|
180
|
+
if (company_id && company_id === '8WX2T4ZJz6JonRNrjhOj') {
|
|
181
|
+
const codigo = urlParams.get('parceiro');
|
|
182
|
+
if (codigo && parameter === 'utm_source') {
|
|
183
|
+
return 'Influenciador';
|
|
184
|
+
}
|
|
185
|
+
else if (codigo && parameter === 'utm_campaign') {
|
|
186
|
+
return codigo;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
}
|
|
192
|
+
if (values.length === 0) {
|
|
193
|
+
return '';
|
|
194
|
+
}
|
|
195
|
+
const prioritizeNumeric = ['utm_campaign', 'sol_campaign', 'utm_content', 'sol_content'];
|
|
196
|
+
if (prioritizeNumeric.includes(parameter) && values.length > 1) {
|
|
197
|
+
const numericValues = values.filter(value => isNumeric(value));
|
|
198
|
+
if (numericValues.length > 0) {
|
|
199
|
+
const maxNumericValue = Math.max(...numericValues.map(Number)).toString();
|
|
200
|
+
return maxNumericValue;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return (_k = values[0]) !== null && _k !== void 0 ? _k : '';
|
|
204
|
+
};
|
|
205
|
+
const generator = () => {
|
|
206
|
+
return Math.random().toString(36).slice(2, 11) + "_" + new Date().getTime();
|
|
207
|
+
};
|
|
208
|
+
export { getCookie, setCookie, generator, getMainDomain, getLocalStorage, getAllStorage, setAllStorage, formatPhone, getCompanyId, getUtmParameter };
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solomon-tech/webanalytics-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Solomon WebAnalytics SDK — browser and Node.js event tracking",
|
|
5
|
+
"main": "./dist/sdk/solomon-sdk.esm.min.js",
|
|
6
|
+
"types": "./dist/sdk/sdk/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/sdk/solomon-sdk.esm.min.js",
|
|
10
|
+
"types": "./dist/sdk/sdk/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./node": {
|
|
13
|
+
"import": "./dist/sdk/solomon-sdk.node.esm.min.js",
|
|
14
|
+
"types": "./dist/sdk/sdk/node/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/sdk"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"watch": "webpack -w",
|
|
22
|
+
"serve": "serve",
|
|
23
|
+
"build": "webpack",
|
|
24
|
+
"build:shopify": "webpack --env platform=shopify",
|
|
25
|
+
"build:shopify-web": "webpack --env platform=shopify-web",
|
|
26
|
+
"build:yampi": "webpack --env platform=yampi",
|
|
27
|
+
"build:nuvemshop": "webpack --env platform=nuvemshop",
|
|
28
|
+
"build:magazord": "webpack --env platform=magazord",
|
|
29
|
+
"build:vtex": "webpack --env platform=vtex",
|
|
30
|
+
"build:magento": "webpack --env platform=magento",
|
|
31
|
+
"build:magento-sdk": "webpack --env platform=magento-sdk",
|
|
32
|
+
"build:hydrogen": "webpack --env platform=hydrogen",
|
|
33
|
+
"build:woocommerce": "webpack --env platform=woocommerce",
|
|
34
|
+
"build:uappi": "webpack --env platform=uappi",
|
|
35
|
+
"build:shoppub": "webpack --env platform=shoppub",
|
|
36
|
+
"build:landing-page": "webpack --env platform=landing-page",
|
|
37
|
+
"build:bagy": "webpack --env platform=bagy",
|
|
38
|
+
"build:wake": "webpack --env platform=wake",
|
|
39
|
+
"build:cartpanda": "webpack --env platform=cartpanda",
|
|
40
|
+
"build:buda": "webpack --env platform=buda",
|
|
41
|
+
"build:wbuy": "webpack --env platform=wbuy",
|
|
42
|
+
"build:trinio": "webpack --env platform=trinio",
|
|
43
|
+
"build:b4you": "webpack --env platform=b4you",
|
|
44
|
+
"build:linx": "webpack --env platform=linx",
|
|
45
|
+
"build:loja_integrada": "webpack --env platform=loja_integrada",
|
|
46
|
+
"build:sdk": "webpack --config webpack.sdk.config.js && npm run build:sdk:types",
|
|
47
|
+
"build:sdk:npm": "webpack --config webpack.sdk.npm.config.js && webpack --config webpack.sdk.node.config.js && npm run build:sdk:types && npm run build:sdk:cleanup",
|
|
48
|
+
"build:sdk:cleanup": "rm -f dist/sdk/types.d.ts dist/sdk/types.js",
|
|
49
|
+
"build:sdk:types": "tsc --project tsconfig.sdk.json",
|
|
50
|
+
"build:sdk:watch": "webpack --config webpack.sdk.config.js --watch",
|
|
51
|
+
"build:sdk:browser": "webpack --config webpack.sdk.browser.config.js",
|
|
52
|
+
"prepublishOnly": "npm run build:sdk:npm"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/jquery": "^3.5.32",
|
|
56
|
+
"serve": "^14.2.3",
|
|
57
|
+
"terser-webpack-plugin": "^5.3.16",
|
|
58
|
+
"ts-loader": "^9.5.1",
|
|
59
|
+
"typescript": "^5.6.2",
|
|
60
|
+
"webpack": "^5.95.0",
|
|
61
|
+
"webpack-cli": "^5.1.4"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@adobe/magento-storefront-events-sdk": "^1.14.0",
|
|
65
|
+
"@shopify/web-pixels-extension": "^2.18.0",
|
|
66
|
+
"jquery": "^3.7.1",
|
|
67
|
+
"uuid": "^11.1.0"
|
|
68
|
+
}
|
|
69
|
+
}
|