@tekibo/feedpulse-sdk 0.4.1 → 0.5.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/dist/index.js +1 -1
- package/dist/index.mjs +223 -69
- package/dist/nuxt.js +1 -1
- package/dist/nuxt.mjs +160 -46
- package/dist/react.js +2 -2
- package/dist/react.mjs +235 -160
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var s in t)r[s]=t[s]}return r}var S={read:function(r){return r[0]==='"'&&(r=r.slice(1,-1)),r.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(r){return encodeURIComponent(r).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function f(r,e){function t(i,o,n){if(!(typeof document>"u")){n=d({},e,n),typeof n.expires=="number"&&(n.expires=new Date(Date.now()+n.expires*864e5)),n.expires&&(n.expires=n.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var u="";for(var l in n)n[l]&&(u+="; "+l,n[l]!==!0&&(u+="="+n[l].split(";")[0]));return document.cookie=i+"="+r.write(o,i)+u}}function s(i){if(!(typeof document>"u"||arguments.length&&!i)){for(var o=document.cookie?document.cookie.split("; "):[],n={},u=0;u<o.length;u++){var l=o[u].split("="),m=l.slice(1).join("=");try{var h=decodeURIComponent(l[0]);if(n[h]=r.read(m,h),i===h)break}catch{}}return i?n[i]:n}}return Object.create({set:t,get:s,remove:function(i,o){t(i,"",d({},o,{expires:-1}))},withAttributes:function(i){return f(this.converter,d({},this.attributes,i))},withConverter:function(i){return f(d({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(r)}})}var c=f(S,{path:"/"});const a={USER_ID:"__fp_uid",SESSION_ID:"__fp_sid",SESSION_START:"__fp_ss",CONSENT:"__fp_consent",UTM:"__fp_utm"},p=1/48,I=365,w=365,k=30;function D(){return typeof window<"u"}function g(r){if(!r)return null;try{return JSON.parse(r)}catch{return null}}class v{initSession(){const e=!!c.get(a.USER_ID);let t=c.get(a.SESSION_ID)??null,s=Number(c.get(a.SESSION_START)||Date.now());return t||(t=crypto.randomUUID(),s=Date.now()),c.set(a.SESSION_ID,t,{expires:p}),c.set(a.SESSION_START,String(s),{expires:p}),{sessionId:t,sessionStart:s,isReturningUser:e}}initUser(){let e=c.get(a.USER_ID)??null;return e||(e=crypto.randomUUID(),c.set(a.USER_ID,e,{expires:w})),e}getConsent(){return g(c.get(a.CONSENT))}setConsent(e){const t={necessary:!0,analytics:e.analytics,marketing:e.marketing,version:e.version,timestamp:Date.now()};return c.set(a.CONSENT,JSON.stringify(t),{expires:I}),t}clearAnalyticsCookies(){c.remove(a.USER_ID)}isConsentExpired(){const e=this.getConsent();if(!e)return!0;const t=365*24*60*60*1e3;return Date.now()-e.timestamp>t}captureUTM(){if(!D())return null;const e=new URLSearchParams(window.location.search),t={};for(const s of["utm_source","utm_medium","utm_campaign","utm_term","utm_content"]){const i=e.get(s);i&&(t[s]=i)}return Object.keys(t).length===0?g(c.get(a.UTM)):(c.set(a.UTM,JSON.stringify(t),{expires:k}),t)}getAllData(e){const{sessionId:t,sessionStart:s,isReturningUser:i}=this.initSession();return{userId:e?this.initUser():null,sessionId:t,sessionStart:s,consent:this.getConsent(),utm:this.captureUTM(),isReturningUser:e?i:!1}}}class b{constructor(e){this.queue=[],this.flushInterval=null,this.sessionId="",this.observer=null,this.intersectionObserver=null,this.scrollFallbackListener=null,this.resizeFallbackListener=null,this.seenInView=new Set,this.cookieManager=new v,this.cookieData=null,this.analyticsConsented=!1,this.isInitialized=!1,this.beforeUnloadListener=null,this.visibilityListener=null;const t="https://feedpulse-workers.tekibohelp.workers.dev/ingest";this.config={apiKey:e.apiKey,endpoint:e.endpoint??t,batchInterval:e.batchInterval??5e3,debug:e.debug??!1}}init(){!this.isBrowser()||this.isInitialized||(this.isInitialized=!0,this.refreshCookieData(),this.startFlushInterval(),this.attachGlobalListeners(),this.observeDOM())}attachGlobalListeners(){document.addEventListener("click",s=>{const i=s.target.closest("[data-fp-id]");i&&this.track("click",i.getAttribute("data-fp-id"),{x:s.clientX,y:s.clientY})},{passive:!0});let e=0,t=null;document.addEventListener("mouseover",s=>{const i=s.target.closest("[data-fp-id]");i&&(e=Date.now(),t=i.getAttribute("data-fp-id"))},{passive:!0}),document.addEventListener("mouseout",s=>{if(!s.target.closest("[data-fp-id]")||!t)return;const o=Date.now()-e;o>500&&this.track("hover",t,{hoverDuration:o}),t=null},{passive:!0})}observeDOM(){const e=i=>{this.seenInView.has(i)||(this.seenInView.add(i),this.track("scroll_into_view",i,{scrollDepth:Math.round(window.scrollY/Math.max(1,document.body.scrollHeight)*100)}))};this.intersectionObserver=new IntersectionObserver(i=>{for(const o of i){const n=o.target.dataset.fpId;!n||!o.isIntersecting||e(n)}},{threshold:.1});const t=()=>{document.querySelectorAll("[data-fp-id]").forEach(i=>{this.intersectionObserver?.observe(i)})},s=()=>{const i=window.innerHeight*.1,o=window.innerHeight*.9;document.querySelectorAll("[data-fp-id]").forEach(n=>{const u=n.dataset.fpId;if(!u||this.seenInView.has(u))return;const l=n.getBoundingClientRect();l.bottom>=i&&l.top<=o&&e(u)})};t(),s(),this.scrollFallbackListener=()=>s(),this.resizeFallbackListener=()=>s(),window.addEventListener("scroll",this.scrollFallbackListener,{passive:!0}),window.addEventListener("resize",this.resizeFallbackListener,{passive:!0}),this.observer=new MutationObserver(()=>t()),this.observer.observe(document.body,{childList:!0,subtree:!0})}track(e,t,s){this.isBrowser()&&(this.refreshCookieData(),this.queue.push({projectApiKey:this.config.apiKey,elementId:t,eventType:e,sessionId:this.cookieData?.sessionId??this.sessionId,visitorId:this.cookieData?.userId??null,isReturningUser:this.cookieData?.isReturningUser??!1,sessionStart:this.cookieData?.sessionStart?new Date(this.cookieData.sessionStart).toISOString():null,utmSource:this.cookieData?.utm?.utm_source??null,utmMedium:this.cookieData?.utm?.utm_medium??null,utmCampaign:this.cookieData?.utm?.utm_campaign??null,utmTerm:this.cookieData?.utm?.utm_term??null,utmContent:this.cookieData?.utm?.utm_content??null,consentAnalytics:this.cookieData?.consent?.analytics??!1,page:window.location.pathname,referrer:document.referrer,device:this.getDeviceType(),browser:this.getBrowser(),os:this.getOS(),metadata:s,timestamp:new Date().toISOString()}))}trackFeedback(e,t,s){this.isBrowser()&&(!t&&!s||(this.refreshCookieData(),this.sendImmediate([{projectApiKey:this.config.apiKey,elementId:e??"__page__",eventType:"feedback",sessionId:this.cookieData?.sessionId??this.sessionId,visitorId:this.cookieData?.userId??null,isReturningUser:this.cookieData?.isReturningUser??!1,sessionStart:this.cookieData?.sessionStart?new Date(this.cookieData.sessionStart).toISOString():null,utmSource:this.cookieData?.utm?.utm_source??null,utmMedium:this.cookieData?.utm?.utm_medium??null,utmCampaign:this.cookieData?.utm?.utm_campaign??null,utmTerm:this.cookieData?.utm?.utm_term??null,utmContent:this.cookieData?.utm?.utm_content??null,consentAnalytics:this.cookieData?.consent?.analytics??!1,page:window.location.pathname,device:this.getDeviceType(),metadata:{rating:t,message:s},timestamp:new Date().toISOString()}])))}async flush(){if(this.queue.length===0)return;const e=[...this.queue];this.queue=[],await this.sendImmediate(e)}async sendImmediate(e){try{const t=await fetch(this.config.endpoint,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({events:e}),keepalive:!0});if(this.config.debug&&t.ok){const s=await t.json().catch(()=>null);s?.ingested!==void 0&&s?.pipeline&&globalThis.console.debug(`[FeedPulse] ${s.ingested} events via ${s.pipeline} pipeline`)}}catch{}}startFlushInterval(){this.flushInterval=setInterval(()=>this.flush(),this.config.batchInterval),this.beforeUnloadListener=()=>this.flush(),this.visibilityListener=()=>{document.visibilityState==="hidden"&&this.flush()},window.addEventListener("beforeunload",this.beforeUnloadListener),document.addEventListener("visibilitychange",this.visibilityListener)}updateCookieData(e){this.cookieData=e,this.sessionId=e.sessionId,this.analyticsConsented=!!e.consent?.analytics}refreshCookieData(){const e=this.cookieManager.getAllData(this.analyticsConsented);this.cookieData=e,this.sessionId=e.sessionId}isBrowser(){return typeof window<"u"&&typeof document<"u"}getDeviceType(){const e=navigator.userAgent;return/Mobi|Android/i.test(e)?"mobile":/Tablet|iPad/i.test(e)?"tablet":"desktop"}getBrowser(){const e=navigator.userAgent;return e.includes("Edg")?"Edge":e.includes("Chrome")?"Chrome":e.includes("Firefox")?"Firefox":e.includes("Safari")?"Safari":"Other"}getOS(){const e=navigator.userAgent;return e.includes("Windows")?"Windows":e.includes("Mac")?"macOS":e.includes("Linux")?"Linux":e.includes("Android")?"Android":/iPhone|iOS/.test(e)?"iOS":"Other"}destroy(){this.flushInterval&&clearInterval(this.flushInterval),this.beforeUnloadListener&&window.removeEventListener("beforeunload",this.beforeUnloadListener),this.visibilityListener&&document.removeEventListener("visibilitychange",this.visibilityListener),this.scrollFallbackListener&&window.removeEventListener("scroll",this.scrollFallbackListener),this.resizeFallbackListener&&window.removeEventListener("resize",this.resizeFallbackListener),this.observer?.disconnect(),this.intersectionObserver?.disconnect(),this.isInitialized=!1,this.flush()}}exports.COOKIE_KEYS=a;exports.CookieManager=v;exports.FeedPulseTracker=b;
|
package/dist/index.mjs
CHANGED
|
@@ -1,92 +1,252 @@
|
|
|
1
|
-
|
|
1
|
+
function d(r) {
|
|
2
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
3
|
+
var t = arguments[e];
|
|
4
|
+
for (var s in t)
|
|
5
|
+
r[s] = t[s];
|
|
6
|
+
}
|
|
7
|
+
return r;
|
|
8
|
+
}
|
|
9
|
+
var v = {
|
|
10
|
+
read: function(r) {
|
|
11
|
+
return r[0] === '"' && (r = r.slice(1, -1)), r.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
12
|
+
},
|
|
13
|
+
write: function(r) {
|
|
14
|
+
return encodeURIComponent(r).replace(
|
|
15
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
16
|
+
decodeURIComponent
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function f(r, e) {
|
|
21
|
+
function t(i, o, n) {
|
|
22
|
+
if (!(typeof document > "u")) {
|
|
23
|
+
n = d({}, e, n), typeof n.expires == "number" && (n.expires = new Date(Date.now() + n.expires * 864e5)), n.expires && (n.expires = n.expires.toUTCString()), i = encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
24
|
+
var u = "";
|
|
25
|
+
for (var l in n)
|
|
26
|
+
n[l] && (u += "; " + l, n[l] !== !0 && (u += "=" + n[l].split(";")[0]));
|
|
27
|
+
return document.cookie = i + "=" + r.write(o, i) + u;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function s(i) {
|
|
31
|
+
if (!(typeof document > "u" || arguments.length && !i)) {
|
|
32
|
+
for (var o = document.cookie ? document.cookie.split("; ") : [], n = {}, u = 0; u < o.length; u++) {
|
|
33
|
+
var l = o[u].split("="), p = l.slice(1).join("=");
|
|
34
|
+
try {
|
|
35
|
+
var h = decodeURIComponent(l[0]);
|
|
36
|
+
if (n[h] = r.read(p, h), i === h)
|
|
37
|
+
break;
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return i ? n[i] : n;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Object.create(
|
|
45
|
+
{
|
|
46
|
+
set: t,
|
|
47
|
+
get: s,
|
|
48
|
+
remove: function(i, o) {
|
|
49
|
+
t(
|
|
50
|
+
i,
|
|
51
|
+
"",
|
|
52
|
+
d({}, o, {
|
|
53
|
+
expires: -1
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
withAttributes: function(i) {
|
|
58
|
+
return f(this.converter, d({}, this.attributes, i));
|
|
59
|
+
},
|
|
60
|
+
withConverter: function(i) {
|
|
61
|
+
return f(d({}, this.converter, i), this.attributes);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
attributes: { value: Object.freeze(e) },
|
|
66
|
+
converter: { value: Object.freeze(r) }
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
var a = f(v, { path: "/" });
|
|
71
|
+
const c = {
|
|
72
|
+
USER_ID: "__fp_uid",
|
|
73
|
+
SESSION_ID: "__fp_sid",
|
|
74
|
+
SESSION_START: "__fp_ss",
|
|
75
|
+
CONSENT: "__fp_consent",
|
|
76
|
+
UTM: "__fp_utm"
|
|
77
|
+
}, m = 1 / 48, I = 365, S = 365, w = 30;
|
|
78
|
+
function k() {
|
|
79
|
+
return typeof window < "u";
|
|
80
|
+
}
|
|
81
|
+
function g(r) {
|
|
82
|
+
if (!r)
|
|
83
|
+
return null;
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(r);
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class D {
|
|
91
|
+
initSession() {
|
|
92
|
+
const e = !!a.get(c.USER_ID);
|
|
93
|
+
let t = a.get(c.SESSION_ID) ?? null, s = Number(a.get(c.SESSION_START) || Date.now());
|
|
94
|
+
return t || (t = crypto.randomUUID(), s = Date.now()), a.set(c.SESSION_ID, t, { expires: m }), a.set(c.SESSION_START, String(s), { expires: m }), { sessionId: t, sessionStart: s, isReturningUser: e };
|
|
95
|
+
}
|
|
96
|
+
initUser() {
|
|
97
|
+
let e = a.get(c.USER_ID) ?? null;
|
|
98
|
+
return e || (e = crypto.randomUUID(), a.set(c.USER_ID, e, { expires: S })), e;
|
|
99
|
+
}
|
|
100
|
+
getConsent() {
|
|
101
|
+
return g(a.get(c.CONSENT));
|
|
102
|
+
}
|
|
103
|
+
setConsent(e) {
|
|
104
|
+
const t = {
|
|
105
|
+
necessary: !0,
|
|
106
|
+
analytics: e.analytics,
|
|
107
|
+
marketing: e.marketing,
|
|
108
|
+
version: e.version,
|
|
109
|
+
timestamp: Date.now()
|
|
110
|
+
};
|
|
111
|
+
return a.set(c.CONSENT, JSON.stringify(t), { expires: I }), t;
|
|
112
|
+
}
|
|
113
|
+
clearAnalyticsCookies() {
|
|
114
|
+
a.remove(c.USER_ID);
|
|
115
|
+
}
|
|
116
|
+
isConsentExpired() {
|
|
117
|
+
const e = this.getConsent();
|
|
118
|
+
if (!e)
|
|
119
|
+
return !0;
|
|
120
|
+
const t = 365 * 24 * 60 * 60 * 1e3;
|
|
121
|
+
return Date.now() - e.timestamp > t;
|
|
122
|
+
}
|
|
123
|
+
captureUTM() {
|
|
124
|
+
if (!k())
|
|
125
|
+
return null;
|
|
126
|
+
const e = new URLSearchParams(window.location.search), t = {};
|
|
127
|
+
for (const s of ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"]) {
|
|
128
|
+
const i = e.get(s);
|
|
129
|
+
i && (t[s] = i);
|
|
130
|
+
}
|
|
131
|
+
return Object.keys(t).length === 0 ? g(a.get(c.UTM)) : (a.set(c.UTM, JSON.stringify(t), { expires: w }), t);
|
|
132
|
+
}
|
|
133
|
+
getAllData(e) {
|
|
134
|
+
const { sessionId: t, sessionStart: s, isReturningUser: i } = this.initSession();
|
|
135
|
+
return {
|
|
136
|
+
userId: e ? this.initUser() : null,
|
|
137
|
+
sessionId: t,
|
|
138
|
+
sessionStart: s,
|
|
139
|
+
consent: this.getConsent(),
|
|
140
|
+
utm: this.captureUTM(),
|
|
141
|
+
isReturningUser: e ? i : !1
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
class _ {
|
|
2
146
|
constructor(e) {
|
|
3
|
-
this.queue = [], this.flushInterval = null, this.observer = null, this.intersectionObserver = null, this.scrollFallbackListener = null, this.resizeFallbackListener = null, this.seenInView = /* @__PURE__ */ new Set();
|
|
4
|
-
const
|
|
147
|
+
this.queue = [], this.flushInterval = null, this.sessionId = "", this.observer = null, this.intersectionObserver = null, this.scrollFallbackListener = null, this.resizeFallbackListener = null, this.seenInView = /* @__PURE__ */ new Set(), this.cookieManager = new D(), this.cookieData = null, this.analyticsConsented = !1, this.isInitialized = !1, this.beforeUnloadListener = null, this.visibilityListener = null;
|
|
148
|
+
const t = "https://feedpulse-workers.tekibohelp.workers.dev/ingest";
|
|
5
149
|
this.config = {
|
|
6
150
|
apiKey: e.apiKey,
|
|
7
|
-
endpoint: e.endpoint ??
|
|
151
|
+
endpoint: e.endpoint ?? t,
|
|
8
152
|
batchInterval: e.batchInterval ?? 5e3,
|
|
9
153
|
debug: e.debug ?? !1
|
|
10
|
-
}
|
|
154
|
+
};
|
|
11
155
|
}
|
|
12
156
|
init() {
|
|
13
|
-
this.isBrowser()
|
|
157
|
+
!this.isBrowser() || this.isInitialized || (this.isInitialized = !0, this.refreshCookieData(), this.startFlushInterval(), this.attachGlobalListeners(), this.observeDOM());
|
|
14
158
|
}
|
|
15
159
|
attachGlobalListeners() {
|
|
16
|
-
document.addEventListener("click", (
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
x:
|
|
20
|
-
y:
|
|
160
|
+
document.addEventListener("click", (s) => {
|
|
161
|
+
const i = s.target.closest("[data-fp-id]");
|
|
162
|
+
i && this.track("click", i.getAttribute("data-fp-id"), {
|
|
163
|
+
x: s.clientX,
|
|
164
|
+
y: s.clientY
|
|
21
165
|
});
|
|
22
166
|
}, { passive: !0 });
|
|
23
|
-
let e = 0,
|
|
24
|
-
document.addEventListener("mouseover", (
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
}, { passive: !0 }), document.addEventListener("mouseout", (
|
|
28
|
-
if (!
|
|
167
|
+
let e = 0, t = null;
|
|
168
|
+
document.addEventListener("mouseover", (s) => {
|
|
169
|
+
const i = s.target.closest("[data-fp-id]");
|
|
170
|
+
i && (e = Date.now(), t = i.getAttribute("data-fp-id"));
|
|
171
|
+
}, { passive: !0 }), document.addEventListener("mouseout", (s) => {
|
|
172
|
+
if (!s.target.closest("[data-fp-id]") || !t)
|
|
29
173
|
return;
|
|
30
|
-
const
|
|
31
|
-
|
|
174
|
+
const o = Date.now() - e;
|
|
175
|
+
o > 500 && this.track("hover", t, { hoverDuration: o }), t = null;
|
|
32
176
|
}, { passive: !0 });
|
|
33
177
|
}
|
|
34
178
|
observeDOM() {
|
|
35
|
-
const e = (
|
|
36
|
-
this.seenInView.has(
|
|
179
|
+
const e = (i) => {
|
|
180
|
+
this.seenInView.has(i) || (this.seenInView.add(i), this.track("scroll_into_view", i, {
|
|
37
181
|
scrollDepth: Math.round(window.scrollY / Math.max(1, document.body.scrollHeight) * 100)
|
|
38
182
|
}));
|
|
39
183
|
};
|
|
40
|
-
this.intersectionObserver = new IntersectionObserver((
|
|
41
|
-
for (const
|
|
42
|
-
const n =
|
|
43
|
-
!n || !
|
|
184
|
+
this.intersectionObserver = new IntersectionObserver((i) => {
|
|
185
|
+
for (const o of i) {
|
|
186
|
+
const n = o.target.dataset.fpId;
|
|
187
|
+
!n || !o.isIntersecting || e(n);
|
|
44
188
|
}
|
|
45
189
|
}, { threshold: 0.1 });
|
|
46
|
-
const
|
|
47
|
-
document.querySelectorAll("[data-fp-id]").forEach((
|
|
48
|
-
this.intersectionObserver?.observe(
|
|
190
|
+
const t = () => {
|
|
191
|
+
document.querySelectorAll("[data-fp-id]").forEach((i) => {
|
|
192
|
+
this.intersectionObserver?.observe(i);
|
|
49
193
|
});
|
|
50
|
-
},
|
|
51
|
-
const
|
|
194
|
+
}, s = () => {
|
|
195
|
+
const i = window.innerHeight * 0.1, o = window.innerHeight * 0.9;
|
|
52
196
|
document.querySelectorAll("[data-fp-id]").forEach((n) => {
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
197
|
+
const u = n.dataset.fpId;
|
|
198
|
+
if (!u || this.seenInView.has(u))
|
|
55
199
|
return;
|
|
56
|
-
const
|
|
57
|
-
|
|
200
|
+
const l = n.getBoundingClientRect();
|
|
201
|
+
l.bottom >= i && l.top <= o && e(u);
|
|
58
202
|
});
|
|
59
203
|
};
|
|
60
|
-
|
|
204
|
+
t(), s(), this.scrollFallbackListener = () => s(), this.resizeFallbackListener = () => s(), window.addEventListener("scroll", this.scrollFallbackListener, { passive: !0 }), window.addEventListener("resize", this.resizeFallbackListener, { passive: !0 }), this.observer = new MutationObserver(() => t()), this.observer.observe(document.body, { childList: !0, subtree: !0 });
|
|
61
205
|
}
|
|
62
|
-
track(e,
|
|
63
|
-
this.isBrowser() && this.queue.push({
|
|
206
|
+
track(e, t, s) {
|
|
207
|
+
this.isBrowser() && (this.refreshCookieData(), this.queue.push({
|
|
64
208
|
projectApiKey: this.config.apiKey,
|
|
65
|
-
elementId:
|
|
209
|
+
elementId: t,
|
|
66
210
|
eventType: e,
|
|
67
|
-
sessionId: this.sessionId,
|
|
68
|
-
visitorId: this.
|
|
211
|
+
sessionId: this.cookieData?.sessionId ?? this.sessionId,
|
|
212
|
+
visitorId: this.cookieData?.userId ?? null,
|
|
213
|
+
isReturningUser: this.cookieData?.isReturningUser ?? !1,
|
|
214
|
+
sessionStart: this.cookieData?.sessionStart ? new Date(this.cookieData.sessionStart).toISOString() : null,
|
|
215
|
+
utmSource: this.cookieData?.utm?.utm_source ?? null,
|
|
216
|
+
utmMedium: this.cookieData?.utm?.utm_medium ?? null,
|
|
217
|
+
utmCampaign: this.cookieData?.utm?.utm_campaign ?? null,
|
|
218
|
+
utmTerm: this.cookieData?.utm?.utm_term ?? null,
|
|
219
|
+
utmContent: this.cookieData?.utm?.utm_content ?? null,
|
|
220
|
+
consentAnalytics: this.cookieData?.consent?.analytics ?? !1,
|
|
69
221
|
page: window.location.pathname,
|
|
70
222
|
referrer: document.referrer,
|
|
71
223
|
device: this.getDeviceType(),
|
|
72
224
|
browser: this.getBrowser(),
|
|
73
225
|
os: this.getOS(),
|
|
74
|
-
metadata:
|
|
226
|
+
metadata: s,
|
|
75
227
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
76
|
-
});
|
|
228
|
+
}));
|
|
77
229
|
}
|
|
78
|
-
trackFeedback(e,
|
|
79
|
-
this.isBrowser() && (!
|
|
230
|
+
trackFeedback(e, t, s) {
|
|
231
|
+
this.isBrowser() && (!t && !s || (this.refreshCookieData(), this.sendImmediate([{
|
|
80
232
|
projectApiKey: this.config.apiKey,
|
|
81
233
|
elementId: e ?? "__page__",
|
|
82
234
|
eventType: "feedback",
|
|
83
|
-
sessionId: this.sessionId,
|
|
84
|
-
visitorId: this.
|
|
235
|
+
sessionId: this.cookieData?.sessionId ?? this.sessionId,
|
|
236
|
+
visitorId: this.cookieData?.userId ?? null,
|
|
237
|
+
isReturningUser: this.cookieData?.isReturningUser ?? !1,
|
|
238
|
+
sessionStart: this.cookieData?.sessionStart ? new Date(this.cookieData.sessionStart).toISOString() : null,
|
|
239
|
+
utmSource: this.cookieData?.utm?.utm_source ?? null,
|
|
240
|
+
utmMedium: this.cookieData?.utm?.utm_medium ?? null,
|
|
241
|
+
utmCampaign: this.cookieData?.utm?.utm_campaign ?? null,
|
|
242
|
+
utmTerm: this.cookieData?.utm?.utm_term ?? null,
|
|
243
|
+
utmContent: this.cookieData?.utm?.utm_content ?? null,
|
|
244
|
+
consentAnalytics: this.cookieData?.consent?.analytics ?? !1,
|
|
85
245
|
page: window.location.pathname,
|
|
86
246
|
device: this.getDeviceType(),
|
|
87
|
-
metadata: { rating:
|
|
247
|
+
metadata: { rating: t, message: s },
|
|
88
248
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
89
|
-
}]));
|
|
249
|
+
}])));
|
|
90
250
|
}
|
|
91
251
|
async flush() {
|
|
92
252
|
if (this.queue.length === 0)
|
|
@@ -96,42 +256,34 @@ class l {
|
|
|
96
256
|
}
|
|
97
257
|
async sendImmediate(e) {
|
|
98
258
|
try {
|
|
99
|
-
const
|
|
259
|
+
const t = await fetch(this.config.endpoint, {
|
|
100
260
|
method: "POST",
|
|
101
261
|
headers: { "content-type": "application/json" },
|
|
102
262
|
body: JSON.stringify({ events: e }),
|
|
103
263
|
keepalive: !0
|
|
104
264
|
});
|
|
105
|
-
if (this.config.debug &&
|
|
106
|
-
const
|
|
107
|
-
|
|
265
|
+
if (this.config.debug && t.ok) {
|
|
266
|
+
const s = await t.json().catch(() => null);
|
|
267
|
+
s?.ingested !== void 0 && s?.pipeline && globalThis.console.debug(`[FeedPulse] ${s.ingested} events via ${s.pipeline} pipeline`);
|
|
108
268
|
}
|
|
109
269
|
} catch {
|
|
110
270
|
}
|
|
111
271
|
}
|
|
112
272
|
startFlushInterval() {
|
|
113
|
-
this.flushInterval = setInterval(() => this.flush(), this.config.batchInterval),
|
|
273
|
+
this.flushInterval = setInterval(() => this.flush(), this.config.batchInterval), this.beforeUnloadListener = () => this.flush(), this.visibilityListener = () => {
|
|
114
274
|
document.visibilityState === "hidden" && this.flush();
|
|
115
|
-
});
|
|
275
|
+
}, window.addEventListener("beforeunload", this.beforeUnloadListener), document.addEventListener("visibilitychange", this.visibilityListener);
|
|
116
276
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
let t = localStorage.getItem(e);
|
|
121
|
-
return t || (t = i, localStorage.setItem(e, t)), t;
|
|
122
|
-
} catch {
|
|
123
|
-
return i;
|
|
124
|
-
}
|
|
277
|
+
updateCookieData(e) {
|
|
278
|
+
this.cookieData = e, this.sessionId = e.sessionId, this.analyticsConsented = !!e.consent?.analytics;
|
|
125
279
|
}
|
|
126
|
-
|
|
127
|
-
|
|
280
|
+
refreshCookieData() {
|
|
281
|
+
const e = this.cookieManager.getAllData(this.analyticsConsented);
|
|
282
|
+
this.cookieData = e, this.sessionId = e.sessionId;
|
|
128
283
|
}
|
|
129
284
|
isBrowser() {
|
|
130
285
|
return typeof window < "u" && typeof document < "u";
|
|
131
286
|
}
|
|
132
|
-
generateSessionId() {
|
|
133
|
-
return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
134
|
-
}
|
|
135
287
|
getDeviceType() {
|
|
136
288
|
const e = navigator.userAgent;
|
|
137
289
|
return /Mobi|Android/i.test(e) ? "mobile" : /Tablet|iPad/i.test(e) ? "tablet" : "desktop";
|
|
@@ -145,9 +297,11 @@ class l {
|
|
|
145
297
|
return e.includes("Windows") ? "Windows" : e.includes("Mac") ? "macOS" : e.includes("Linux") ? "Linux" : e.includes("Android") ? "Android" : /iPhone|iOS/.test(e) ? "iOS" : "Other";
|
|
146
298
|
}
|
|
147
299
|
destroy() {
|
|
148
|
-
this.flushInterval && clearInterval(this.flushInterval), this.scrollFallbackListener && window.removeEventListener("scroll", this.scrollFallbackListener), this.resizeFallbackListener && window.removeEventListener("resize", this.resizeFallbackListener), this.observer?.disconnect(), this.intersectionObserver?.disconnect(), this.flush();
|
|
300
|
+
this.flushInterval && clearInterval(this.flushInterval), this.beforeUnloadListener && window.removeEventListener("beforeunload", this.beforeUnloadListener), this.visibilityListener && document.removeEventListener("visibilitychange", this.visibilityListener), this.scrollFallbackListener && window.removeEventListener("scroll", this.scrollFallbackListener), this.resizeFallbackListener && window.removeEventListener("resize", this.resizeFallbackListener), this.observer?.disconnect(), this.intersectionObserver?.disconnect(), this.isInitialized = !1, this.flush();
|
|
149
301
|
}
|
|
150
302
|
}
|
|
151
303
|
export {
|
|
152
|
-
|
|
304
|
+
c as COOKIE_KEYS,
|
|
305
|
+
D as CookieManager,
|
|
306
|
+
_ as FeedPulseTracker
|
|
153
307
|
};
|
package/dist/nuxt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),y=require("./index.js"),x=Symbol("feedpulse");function v(){return e.inject(x,null)}const w={key:0,style:{position:"fixed",bottom:"0",left:"0",right:"0","z-index":"99999",background:"#1a1a1a",color:"#fff",padding:"20px 24px","border-top":"1px solid #333","font-family":"sans-serif"}},C={style:{"max-width":"900px",margin:"0 auto"}},E={key:0,style:{"margin-bottom":"12px","font-size":"13px"}},h={style:{display:"flex","align-items":"center",gap:"8px","margin-bottom":"6px"}},V={style:{display:"flex","align-items":"center",gap:"8px"}},N={style:{display:"flex",gap:"8px","flex-wrap":"wrap","align-items":"center"}},b=e.defineComponent({__name:"consent-banner",emits:["consent"],setup(s,{emit:r}){const o=r,n=new y.CookieManager,a=e.ref(!1),t=e.ref(!1),i=e.ref(!1),c=e.ref(!1);function f(){a.value=!0,t.value=!0}e.onMounted(()=>{const p=n.getConsent();a.value=!p||n.isConsentExpired(),p&&(i.value=p.analytics,c.value=p.marketing),typeof window<"u"&&(window.addEventListener("feedpulse:open-consent",f),window.addEventListener("feedpulse:withdraw-consent",k))});function m(){n.setConsent({analytics:!0,marketing:!0,version:"1.0"}),o("consent",{analytics:!0,marketing:!0,action:"accept_all"}),a.value=!1}function d(){n.setConsent({analytics:!1,marketing:!1,version:"1.0"}),n.clearAnalyticsCookies(),o("consent",{analytics:!1,marketing:!1,action:"reject_all"}),a.value=!1}function u(){n.setConsent({analytics:i.value,marketing:c.value,version:"1.0"}),i.value||n.clearAnalyticsCookies(),o("consent",{analytics:i.value,marketing:c.value,action:"custom"}),a.value=!1}function k(){n.setConsent({analytics:!1,marketing:!1,version:"1.0"}),n.clearAnalyticsCookies(),i.value=!1,c.value=!1,o("consent",{analytics:!1,marketing:!1,action:"withdraw"}),a.value=!0}return e.onBeforeUnmount(()=>{typeof window<"u"&&(window.removeEventListener("feedpulse:open-consent",f),window.removeEventListener("feedpulse:withdraw-consent",k))}),(p,l)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[a.value?(e.openBlock(),e.createElementBlock("div",w,[e.createElementVNode("div",C,[l[6]||(l[6]=e.createElementVNode("p",{style:{margin:"0 0 12px","font-size":"14px","line-height":"1.5"}},[e.createTextVNode(" We use cookies to improve reliability and understand usage. "),e.createElementVNode("a",{href:"/privacy",style:{color:"#818cf8"}},"Privacy Policy")],-1)),t.value?(e.openBlock(),e.createElementBlock("div",E,[l[5]||(l[5]=e.createElementVNode("label",{style:{display:"flex","align-items":"center",gap:"8px","margin-bottom":"6px",opacity:"0.75"}},[e.createElementVNode("input",{type:"checkbox",checked:"",disabled:""}),e.createTextVNode(" Necessary (always on) ")],-1)),e.createElementVNode("label",h,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":l[0]||(l[0]=g=>i.value=g),type:"checkbox"},null,512),[[e.vModelCheckbox,i.value]]),l[3]||(l[3]=e.createTextVNode(" Analytics ",-1))]),e.createElementVNode("label",V,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":l[1]||(l[1]=g=>c.value=g),type:"checkbox"},null,512),[[e.vModelCheckbox,c.value]]),l[4]||(l[4]=e.createTextVNode(" Marketing ",-1))])])):e.createCommentVNode("",!0),e.createElementVNode("div",N,[e.createElementVNode("button",{style:{width:"130px",padding:"9px 12px",background:"#4f46e5",color:"#fff",border:"1px solid #4f46e5","border-radius":"6px","font-size":"13px","font-weight":"600",cursor:"pointer"},onClick:m}," Accept All "),e.createElementVNode("button",{style:{width:"130px",padding:"9px 12px",background:"transparent",color:"#fff",border:"1px solid #555","border-radius":"6px","font-size":"13px","font-weight":"600",cursor:"pointer"},onClick:d}," Reject All "),e.createElementVNode("button",{style:{padding:"9px 16px",background:"transparent",color:"#aaa",border:"1px solid #333","border-radius":"6px","font-size":"13px",cursor:"pointer"},onClick:l[2]||(l[2]=g=>t.value?u():t.value=!0)},e.toDisplayString(t.value?"Save Preferences":"Customize"),1)])])])):e.createCommentVNode("",!0)]))}}),B=e.defineComponent({__name:"FeedPulseProvider",props:{apiKey:{},endpoint:{},debug:{type:Boolean},consentRequired:{type:Boolean,default:!0}},setup(s){const r=s,o=new y.CookieManager,n=new y.FeedPulseTracker({apiKey:r.apiKey,endpoint:r.endpoint,debug:r.debug});e.provide(x,n);function a(t){const i=o.setConsent({analytics:t.analytics,marketing:t.marketing,version:"1.0"});t.analytics||o.clearAnalyticsCookies(),n.updateCookieData(o.getAllData(t.analytics)),n.track("consent","__consent__",{analytics:t.analytics,marketing:t.marketing,action:t.action,userAgent:navigator.userAgent,version:i.version})}return e.onMounted(()=>{const t=o.getConsent();r.consentRequired===!1?(o.setConsent({analytics:!0,marketing:!0,version:"1.0"}),n.updateCookieData(o.getAllData(!0))):t&&!o.isConsentExpired()?n.updateCookieData(o.getAllData(t.analytics)):n.updateCookieData(o.getAllData(!1)),n.init()}),e.onBeforeUnmount(()=>n.destroy()),(t,i)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(t.$slots,"default"),s.consentRequired!==!1?(e.openBlock(),e.createBlock(b,{key:0,onConsent:a})):e.createCommentVNode("",!0)],64))}}),_={key:1,style:{background:"#fff",border:"1px solid #e5e7eb","border-radius":"12px",padding:"16px",width:"280px","box-shadow":"0 10px 25px rgba(0,0,0,0.15)"}},A={style:{margin:"0 0 12px","font-weight":"600",color:"#111"}},z={style:{display:"flex",gap:"6px","margin-bottom":"12px"}},D=["onClick"],P={key:1,style:{"text-align":"center",padding:"16px",color:"#111"}},F=e.defineComponent({__name:"FeedPulseWidget",props:{id:{},placeholder:{},position:{default:"bottom-right"}},setup(s){const r=s,o=v(),n=e.ref(r.position==="inline"),a=e.ref(null),t=e.ref(""),i=e.ref(!1);function c(m){a.value=m}function f(){!a.value&&!t.value.trim()||(o?.trackFeedback(r.id??null,a.value,t.value||null),i.value=!0,setTimeout(()=>{n.value=r.position==="inline",i.value=!1,a.value=null,t.value=""},2e3))}return(m,d)=>(e.openBlock(),e.createElementBlock("div",{class:"feedpulse-widget",style:e.normalizeStyle(s.position!=="inline"?`position:fixed; ${s.position==="bottom-right"?"right:24px":"left:24px"}; bottom:24px; z-index:9999;`:"")},[s.position!=="inline"?(e.openBlock(),e.createElementBlock("button",{key:0,style:{background:"#6366f1",color:"#fff",border:"none","border-radius":"50%",width:"48px",height:"48px","font-size":"20px",cursor:"pointer"},onClick:d[0]||(d[0]=u=>n.value=!n.value)}," 💬 ")):e.createCommentVNode("",!0),n.value?(e.openBlock(),e.createElementBlock("div",_,[i.value?(e.openBlock(),e.createElementBlock("div",P,[...d[2]||(d[2]=[e.createElementVNode("p",{style:{"font-size":"28px",margin:"0"}}," 🎉 ",-1),e.createElementVNode("p",{style:{margin:"8px 0 0","font-weight":"600"}}," Thanks for your feedback! ",-1)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("p",A,e.toDisplayString(s.placeholder??"How was your experience?"),1),e.createElementVNode("div",z,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(5,u=>e.createElementVNode("button",{key:u,style:e.normalizeStyle({background:"none",border:"none",cursor:"pointer",fontSize:"24px",opacity:a.value!==null&&u<=a.value?1:.3}),onClick:k=>c(u)}," ⭐ ",12,D)),64))]),e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":d[1]||(d[1]=u=>t.value=u),placeholder:"Tell us more (optional)...",rows:"3",style:{width:"100%",padding:"8px",border:"1px solid #d1d5db","border-radius":"8px",resize:"none","font-size":"14px"}},null,512),[[e.vModelText,t.value]]),e.createElementVNode("button",{style:{"margin-top":"10px",width:"100%",background:"#6366f1",color:"#fff",border:"none","border-radius":"8px",padding:"10px","font-weight":"600",cursor:"pointer"},onClick:f}," Submit Feedback ")],64))])):e.createCommentVNode("",!0)],4))}});exports.ConsentBanner=b;exports.FeedPulseProvider=B;exports.FeedPulseWidget=F;exports.useFeedPulse=v;
|