@rockfeller/sdk 0.1.0 → 0.1.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,6 +1,6 @@
|
|
|
1
1
|
export declare const STORAGE_KEY = "rmv_visitor_id";
|
|
2
2
|
export declare const SESSION_KEY = "rmv_session_id";
|
|
3
|
-
export declare const DEFAULT_API_URL = "https://api.
|
|
3
|
+
export declare const DEFAULT_API_URL = "https://rockmarketvisor-api-s49u7b-4bd126-164-92-91-211.traefik.me";
|
|
4
4
|
export declare const ID_PREFIX = "rmv_";
|
|
5
5
|
export declare const ID_LENGTH = 20;
|
|
6
6
|
export declare const CONFIG_CACHE_KEY = "rmv_config";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.constants.d.ts","sourceRoot":"","sources":["../../src/constants/sdk.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAC5C,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAC5C,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"sdk.constants.d.ts","sourceRoot":"","sources":["../../src/constants/sdk.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAC5C,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAC5C,eAAO,MAAM,eAAe,uEAAuE,CAAC;AACpG,eAAO,MAAM,SAAS,SAAS,CAAC;AAChC,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,gBAAgB,QAAgB,CAAC;AAE9C,eAAO,MAAM,QAAQ,+GASX,CAAC;AAEX,eAAO,MAAM,oBAAoB,0HAKvB,CAAC;AAEX,eAAO,MAAM,oBAAoB,4KAOvB,CAAC;AAEX,eAAO,MAAM,mBAAmB,mIAKtB,CAAC;AAEX,eAAO,MAAM,kBAAkB,iEAGrB,CAAC"}
|
package/dist/sdk.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const I = "rmv_visitor_id", h = "rmv_session_id", E = "https://api.
|
|
1
|
+
const I = "rmv_visitor_id", h = "rmv_session_id", E = "https://rockmarketvisor-api-s49u7b-4bd126-164-92-91-211.traefik.me", K = "rmv_";
|
|
2
2
|
const y = "rmv_config";
|
|
3
3
|
const q = [
|
|
4
4
|
"utm_source",
|
package/dist/sdk.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.TrackFlow={}))})(this,(function(l){"use strict";const u="rmv_visitor_id",I="rmv_session_id",y="https://api.
|
|
1
|
+
(function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.TrackFlow={}))})(this,(function(l){"use strict";const u="rmv_visitor_id",I="rmv_session_id",y="https://rockmarketvisor-api-s49u7b-4bd126-164-92-91-211.traefik.me",M="rmv_",v="rmv_config",j=["utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_id","gclid","fbclid"],U=['input[type="email"]','input[name*="email"]','input[name*="e-mail"]','input[autocomplete="email"]'],x=['input[type="tel"]','input[name*="phone"]','input[name*="tel"]','input[name*="celular"]','input[name*="whatsapp"]','input[autocomplete="tel"]'],N=['input[name*="name"]','input[name*="nome"]','input[autocomplete="name"]','input[autocomplete="given-name"]'],R=['input[name*="cpf"]','input[name*="documento"]'],o={publicKey:null,apiUrl:y,debug:!1,projectId:null,franchiseId:null,visitorId:null,sessionId:null,remoteConfig:null,initialized:!1};function H(){o.publicKey=null,o.apiUrl=y,o.debug=!1,o.projectId=null,o.franchiseId=null,o.visitorId=null,o.sessionId=null,o.remoteConfig=null,o.initialized=!1}function c(...e){o.debug&&console.log("[TrackFlow]",...e)}function k(){const e=new URLSearchParams(window.location.search),t={};for(const n of j){const i=e.get(n);i&&(t[n]=i)}return t}let p=!1,b=null,g=null;function D(e){var s;if(!e.enabled||p)return;const t=!!e.adsId,n=!!e.analyticsId;if(!t&&!n)return;const i=e.adsId??e.analyticsId;c("[Google] Carregando:",i),window.dataLayer=window.dataLayer||[],window.gtag=function(...f){window.dataLayer.push(f)},window.gtag("js",new Date);const r=document.createElement("script");r.async=!0,r.src=`https://www.googletagmanager.com/gtag/js?id=${i}`;const a=document.getElementsByTagName("script")[0];(s=a==null?void 0:a.parentNode)==null||s.insertBefore(r,a),t&&(window.gtag("config",e.adsId),g=e.adsId,b=e.conversionLabel),n&&window.gtag("config",e.analyticsId),p=!0,c("[Google] Inicializado")}function $(){!p||!window.gtag||window.gtag("event","page_view")}function z(e){!p||!window.gtag||window.gtag("event","generate_lead",e)}function G(e,t="BRL"){if(!p||!window.gtag||!g)return;const n={send_to:b?`${g}/${b}`:g,value:e,currency:t};window.gtag("event","conversion",n)}function B(e,t){!p||!window.gtag||window.gtag("event",e,t)}let m=!1;function V(e){var s;if(!e.enabled||!e.pixelId||m)return;c("[Meta Pixel] Carregando:",e.pixelId);const t=window,n=document;if(typeof t.fbq=="function")return;const i=t.fbq=(...f)=>{i.callMethod?i.callMethod.apply(i,f):i.queue.push(f)};t._fbq||(t._fbq=i),i.push=i,i.loaded=!0,i.version="2.0",i.queue=[];const r=n.createElement("script");r.async=!0,r.src="https://connect.facebook.net/en_US/fbevents.js";const a=n.getElementsByTagName("script")[0];(s=a==null?void 0:a.parentNode)==null||s.insertBefore(r,a),window.fbq("init",e.pixelId),window.fbq("track","PageView"),m=!0,c("[Meta Pixel] Inicializado")}function Y(){!m||!window.fbq||window.fbq("track","PageView")}function J(e){!m||!window.fbq||window.fbq("track","Lead",e)}function X(e,t="BRL"){!m||!window.fbq||window.fbq("track","Purchase",{value:e,currency:t})}function W(e,t){!m||!window.fbq||window.fbq("trackCustom",e,t)}function Q(e){V(e.pixels.meta),D(e.pixels.google)}function Z(){Y(),$()}function ee(e){J(e),z(e)}function te(e,t="BRL"){X(e,t),G(e,t)}function C(e,t){W(e,t),B(e,t)}function L(){return M+crypto.randomUUID().replace(/-/g,"").slice(0,20)}function S(){if(o.visitorId)return o.visitorId;try{const e=localStorage.getItem(u);if(e)return o.visitorId=e,e}catch{}o.visitorId=L();try{localStorage.setItem(u,o.visitorId)}catch{}return o.visitorId}function F(){if(o.sessionId)return o.sessionId;try{const e=sessionStorage.getItem(I);if(e)return o.sessionId=e,e}catch{}o.sessionId=L();try{sessionStorage.setItem(I,o.sessionId)}catch{}return o.sessionId}function ne(){try{localStorage.removeItem(u),sessionStorage.removeItem(I)}catch{}}async function d(e,t){if(!o.initialized||!o.projectId){console.warn("[TrackFlow] SDK nao inicializado. Chame TrackFlow.init() primeiro.");return}const n=`${o.apiUrl}${e}`,i={...t,projectId:o.projectId,visitorId:S(),sessionId:F(),franchiseId:o.franchiseId,timestamp:new Date().toISOString()};c(`-> ${e}`,i);try{const r={"Content-Type":"application/json"};o.publicKey&&(r["X-API-Key"]=o.publicKey);const a=await fetch(n,{method:"POST",headers:r,body:JSON.stringify(i),keepalive:!0});a.ok||c(`Erro ${a.status}:`,await a.text())}catch(r){c("Erro ao enviar evento:",r)}}function w(e){d("/api/events",{type:"pageview",properties:{title:document.title,path:window.location.pathname,search:window.location.search,referrer:document.referrer,...k(),...e},url:window.location.href,referrer:document.referrer}),Z()}function oe(e,t){d("/api/events",{type:e,properties:t??{},url:window.location.href}),C(e,t)}function A(e){d("/api/identify",{...e,visitorId:S()})}function ie(e,t,n){d("/api/conversions",{type:e,value:t,properties:n??{}}),te(t),C(e,{value:t,...n})}const O=new WeakSet;function h(e,t){var n;for(const i of t){const r=e.querySelector(i);if((n=r==null?void 0:r.value)!=null&&n.trim())return r.value.trim()}}function re(e){const t=e.target;if(!t||!(t instanceof HTMLFormElement))return;const n={};if(n.email=h(t,U),n.phone=h(t,x),n.name=h(t,N),n.cpf=h(t,R),!n.email&&!n.phone){c("[AutoIdentify] Form sem email ou telefone, ignorando");return}c("[AutoIdentify] Lead detectado:",n),A(n),ee({content_name:n.email??n.phone,email:n.email})}function _(e){O.has(e)||(O.add(e),e.addEventListener("submit",re),c("[AutoIdentify] Observando form:",e.action||e.id||"(sem id)"))}function ae(){document.querySelectorAll("form").forEach(_),new MutationObserver(n=>{for(const i of n)i.addedNodes.forEach(r=>{r instanceof HTMLFormElement&&_(r),r instanceof HTMLElement&&r.querySelectorAll("form").forEach(_)})}).observe(document.body,{childList:!0,subtree:!0}),c("[AutoIdentify] Ativo")}function ce(){try{const e=localStorage.getItem(v);if(!e)return null;const t=JSON.parse(e);return Date.now()-t.cachedAt>3e5?(localStorage.removeItem(v),null):t.data}catch{return null}}function se(e){try{const t={data:e,cachedAt:Date.now()};localStorage.setItem(v,JSON.stringify(t))}catch{}}async function le(){if(!o.publicKey)return null;const e=ce();if(e)return c("[Config] Usando cache local"),e;try{const t=`${o.apiUrl}/api/sdk/config?key=${o.publicKey}`;c("[Config] Buscando:",t);const n=await fetch(t);if(!n.ok)return c(`[Config] Erro ${n.status}`),null;const i=await n.json();if(!i.success||!i.data)return null;const r=i.data;return se(r),c("[Config] Carregada:",r),r}catch(t){return c("[Config] Erro ao buscar:",t),null}}const E=new Set;function ue(e=[25,50,75,100]){let t=!1;function n(){const i=document.documentElement.scrollHeight-window.innerHeight;if(i<=0)return;const r=Math.round(window.scrollY/i*100);for(const a of e)r>=a&&!E.has(a)&&(E.add(a),c(`[Scroll] ${a}%`),d("/api/events",{type:"scroll_depth",properties:{depth:a},url:window.location.href}))}window.addEventListener("scroll",()=>{t||(t=!0,requestAnimationFrame(()=>{n(),t=!1}))},{passive:!0}),c("[Scroll] Tracking ativo:",e)}function P(){E.clear()}async function T(e){if(o.initialized){c("SDK ja inicializado, ignorando.");return}o.publicKey=e.publicKey,o.apiUrl=e.apiUrl??y,o.debug=e.debug??!1,S(),F();const t=k();t.utm_id&&(o.franchiseId=t.utm_id);const n=await le();n&&(o.projectId=n.projectId,o.remoteConfig=n,Q(n)),o.initialized=!0,c("Inicializado",{publicKey:o.publicKey,projectId:o.projectId,visitorId:o.visitorId,franchiseId:o.franchiseId}),Object.keys(t).length>0&&d("/api/events",{type:"utm_capture",properties:t,url:window.location.href,referrer:document.referrer});const i=(n==null?void 0:n.features)??{autoPageview:!0,autoIdentify:!0,autoScroll:!1,scrollThresholds:[25,50,75,100]};if(i.autoPageview){w();const r=history.pushState;history.pushState=function(...a){r.apply(this,a),P(),w()},window.addEventListener("popstate",()=>{P(),w()})}i.autoIdentify&&ae(),i.autoScroll&&ue(i.scrollThresholds),document.addEventListener("click",r=>{var f,q;const a=(f=r.target)==null?void 0:f.closest("[data-tf-track]");if(!a)return;const s=a.dataset.tfTrack;s&&d("/api/events",{type:s,properties:{text:(q=a.textContent)==null?void 0:q.trim().slice(0,100),href:a instanceof HTMLAnchorElement?a.href:void 0},url:window.location.href})})}function de(){ne(),H()}function fe(){return o.visitorId}function pe(){if(typeof document>"u")return;const e=document.currentScript;if(e!=null&&e.dataset.key){T({publicKey:e.dataset.key,apiUrl:e.dataset.apiUrl,debug:e.dataset.debug==="true"});return}const t=window.TrackFlowConfig;t!=null&&t.publicKey&&T({publicKey:t.publicKey,apiUrl:t.apiUrl,debug:t.debug===!0})}const K={init:T,page:w,track:oe,identify:A,conversion:ie,reset:de,getVisitorId:fe};pe(),l.TrackFlow=K,l.default=K,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|