@webority/analytics 0.37.0 → 0.38.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.
- package/dist/check-events.js +14 -14
- package/dist/chunk-NCVTY7BB.js +1 -0
- package/dist/chunk-S6QAWBSZ.js +1 -0
- package/dist/errors.js +1 -1
- package/dist/generate-events.js +12 -12
- package/dist/index.js +1 -1
- package/dist/node.js +1 -1
- package/dist/react-native.js +1 -1
- package/dist/site.js +1 -1
- package/dist/types/after-interaction.d.ts +6 -0
- package/dist/types/analytics.d.ts +49 -0
- package/dist/types/attribution.d.ts +34 -0
- package/dist/types/catalogue/check-events.d.ts +2 -0
- package/dist/types/catalogue/check.d.ts +32 -0
- package/dist/types/catalogue/generate-events.d.ts +2 -0
- package/dist/types/catalogue/generate.d.ts +28 -0
- package/dist/types/catalogue/plan.d.ts +97 -0
- package/dist/types/catalogue/scan.d.ts +42 -0
- package/dist/types/channels.d.ts +24 -0
- package/dist/types/consent-regions.d.ts +2 -0
- package/dist/types/consent.d.ts +83 -0
- package/dist/types/errors.d.ts +36 -0
- package/dist/types/event-registry.d.ts +19 -0
- package/dist/types/feature-flags.d.ts +26 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/node/errors.d.ts +39 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/posthog-bridge.d.ts +25 -0
- package/dist/types/react-native/index.d.ts +90 -0
- package/dist/types/react-native/native-modules.d.ts +41 -0
- package/dist/types/site-events.d.ts +16 -0
- package/dist/types/site-posthog-snippet.d.ts +27 -0
- package/dist/types/site-posthog.d.ts +61 -0
- package/dist/types/site-web-vitals-script.d.ts +13 -0
- package/dist/types/site-web-vitals.d.ts +4 -0
- package/dist/types/site.d.ts +8 -0
- package/dist/types/state.d.ts +43 -0
- package/dist/types/tags.d.ts +35 -0
- package/dist/types/tours.d.ts +8 -0
- package/dist/types/track-helpers.d.ts +8 -0
- package/dist/types/url-scrub.d.ts +14 -0
- package/dist/types/vocabulary.d.ts +76 -0
- package/dist/types/web-vitals-global.d.ts +1 -0
- package/dist/types/web-vitals.d.ts +107 -0
- package/dist/{web-vitals-RMISAXOY.js → web-vitals-ET2TNTYN.js} +1 -1
- package/dist/webority-analytics-site.global.js +1 -1
- package/dist/webority-analytics-web-vitals.global.js +1 -1
- package/package.json +30 -11
- package/dist/chunk-BXYJOYLR.js +0 -1
- package/dist/chunk-TPTUIQE4.js +0 -1
package/dist/check-events.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{readFileSync as
|
|
3
|
-
`&&
|
|
4
|
-
`,n)+1;for(let
|
|
5
|
-
`),
|
|
6
|
-
`,
|
|
7
|
-
`);
|
|
8
|
-
`,s+1))n.push(s);return s=>{let o=0,t=n.length;for(;o<t;){let r=o+t>>>1;n[r]<s?o=r+1:t=r}return o+1}}function G(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ye={csharp:new Set([".cs"]),javascript:new Set([".js",".jsx",".mjs",".cjs",".ts",".tsx",".html",".cshtml",".razor"])},be="trackSiteEvent",Oe=/^(node_modules|bin|obj|dist|build|coverage|\.git|\.expo|__tests__|__mocks__|tests?)$|\.Tests?$/i,De=/\.(test|spec)\.[cm]?[jt]sx?$|\.d\.ts$/i;function Ce(e){let n=new Map;for(let[s,o]of e.events)o.origin==="fleet"&&n.set(Ne(s),s);return n}function Y(e,n){let s=[],o=(i,c,a)=>s.push({file:i?Z(V(n,i)):null,line:c,message:a}),t=Ce(e),r={constants:0,callSites:0,files:0};for(let i of e.sources){let c=new Map,a=new Set(i.ignoreConstants??[]),l=new Set;for(let T of i.constants??[]){let E=x(n,T);if(l.add(E),!H(E)){o(null,null,`${i.sender}: constants file ${T} does not exist`);continue}let h=z(E,"utf8"),S=i.language==="csharp"?w(h,t):U(h);for(let p of S){if(a.has(p.name))continue;if(r.constants++,p.value===null){o(E,p.line,`${p.name} is not a string literal or an AnalyticsEvents constant, so its event name cannot be read`);continue}if(!D.test(p.value)){o(E,p.line,`${p.name} = "${p.value}" is not a snake_case event name (list it in ignoreConstants if it is not an event)`);continue}e.events.has(p.value)||o(E,p.line,`event "${p.value}" (${p.name}) is not in the ${e.product} tracking plan`);let g=c.get(p.name);g!==void 0&&g!==p.value&&o(E,p.line,`${p.name} is declared twice with different events ("${g}" and "${p.value}")`),c.set(p.name,p.value)}}let f=i.references??[],d=i.language==="csharp",_=d?[...new Set([...f,"AnalyticsEvents"])]:f,A=i.language==="javascript"?[...new Set([...i.calls??[],be])]:i.calls??[];if(_.length===0&&A.length===0)continue;let L=(T,E,h,S)=>{let p=e.events.get(h);if(p){p.senders.includes(i.sender)||o(T,E,`event "${h}" is sent by ${i.sender}, which its plan entry does not list as a sender`);for(let g of S??[])!p.properties.has(g)&&!e.commonProperties.has(g)&&o(T,E,`event "${h}" sends property "${g}", which the plan does not declare`)}};for(let T of i.scan??[]){let E=x(n,T);if(!H(E)){o(null,null,`${i.sender}: scan folder ${T} does not exist`);continue}for(let h of q(E,ye[i.language],i.exclude??[],n)){if(l.has(h))continue;r.files++;let S=z(h,"utf8");for(let p of M(S,_,i.language)){if(a.has(p.constant))continue;let g=c.get(p.constant)??(d?t.get(p.constant):void 0);if(g===void 0){i.language==="javascript"&&o(h,p.line,`${p.constant} is not an event constant in ${i.constants.join(", ")}`);continue}r.callSites++,L(h,p.line,g,p.properties)}for(let p of F(S,A,i.language)){if(r.callSites++,!e.events.has(p.name)){o(h,p.line,`event "${p.name}" (sent through ${p.call}) is not in the ${e.product} tracking plan`);continue}L(h,p.line,p.name,p.properties)}}}}return{problems:s,summary:r}}function*q(e,n,s,o){let t=Ae(e,{withFileTypes:!0}).sort((r,i)=>r.name<i.name?-1:r.name>i.name?1:0);for(let r of t){let i=$e(e,r.name),c=Z(V(o,i));s.some(a=>c===a||c.startsWith(`${a}/`)||r.name===a)||(r.isDirectory()?Oe.test(r.name)||(yield*q(i,n,s,o)):r.isFile()&&n.has(ve(r.name))&&!De.test(r.name)&&(yield i))}}function ve(e){let n=e.lastIndexOf(".");return n===-1?"":e.slice(n).toLowerCase()}function J(e){let n=W(x(e));return Te(n)===".webority"?W(n):n}function Ne(e){return e.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function Z(e){return e.split(Se).join("/")}import{readFileSync as Pe}from"node:fs";import{dirname as Re,resolve as te}from"node:path";var ne="@webority/analytics/fleet",Q=Object.freeze(["acquisition","activation","engagement","retention","revenue","referral","support","quality"]),R=Object.freeze(["none","pseudonymous","personal"]),X=Object.freeze(["string","integer","number","boolean","array","object"]),se=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,oe=new Set(["properties","senders"]),Ie=new Set(["$schema","product","extends","description","commonProperties","events","sources"]),xe=new Set(["description","stage","owner","personalData","senders","properties"]),ke=new Set(["type","description","values","nullable","personalData"]),je=new Set(["sender","language","constants","references","calls","ignoreConstants","scan","exclude"]),Le=/^[A-Za-z_$][\w$]*$/,we=new Set(["csharp","javascript"]),ee=4,Ue=new URL("./fleet-tracking-plan.json",import.meta.url);function re(e){return ie(te(e),0)}function ie(e,n){let s=typeof e=="string"?e:"fleet-tracking-plan.json",o=[],t;try{t=JSON.parse(Pe(e,"utf8"))}catch(c){return{plan:null,problems:[`${s}: cannot read the plan (${c.message})`]}}if(o.push(...Fe(t,s)),o.length>0)return{plan:null,problems:o};let r=null;if(t.extends!==void 0){if(n>=ee)return{plan:null,problems:[`${s}: "extends" is nested more than ${ee} deep`]};let c=t.extends===ne?Ue:te(Re(String(e)),t.extends),a=ie(c,n+1);if(!a.plan)return{plan:null,problems:a.problems};r=a.plan}let i=Me(r,t,s);return{plan:i.plan,problems:i.problems}}function Me(e,n,s="plan"){let o=[],t=new Map,r=new Map(e?.commonProperties??[]);for(let[a,l]of e?.events??[])t.set(a,{...l,properties:new Map(l.properties),senders:[...l.senders]});for(let[a,l]of Object.entries(n.commonProperties??{})){let f=r.get(a);if(f&&f.type!==l.type){o.push(`${s}: common property "${a}" is ${l.type} here but ${f.type} in the base plan`);continue}r.set(a,{...l,origin:f?.origin??n.product})}for(let[a,l]of Object.entries(n.events??{})){let f=t.get(a);if(!f){let d=["description","stage","owner","personalData"].filter(_=>l[_]===void 0);d.length>0&&o.push(`${s}: event "${a}" is not in the base plan, so it needs description, stage, owner and personalData (missing ${d.join(", ")})`),t.set(a,{name:a,description:l.description,stage:l.stage,owner:l.owner,personalData:l.personalData,senders:[...l.senders??[]],properties:new Map(Object.entries(l.properties??{})),origin:n.product});continue}for(let d of Object.keys(l))oe.has(d)||o.push(`${s}: event "${a}" is defined by the base plan, so it may only add properties or senders (found "${d}")`);for(let d of l.senders??[])f.senders.includes(d)||f.senders.push(d);for(let[d,_]of Object.entries(l.properties??{})){let A=f.properties.get(d);if(A&&A.type!==_.type){o.push(`${s}: "${a}.${d}" is ${_.type} here but ${A.type} in the base plan`);continue}f.properties.set(d,_)}}for(let[a,l]of t)for(let f of l.properties.keys())r.has(f)&&o.push(`${s}: "${a}.${f}" is already a common property, so it must not be declared on the event`);let i=n.sources??[],c=new Set(i.map(a=>a.sender));if(i.length>0)for(let[a,l]of Object.entries(n.events??{}))for(let f of l.senders??[])c.has(f)||o.push(`${s}: event "${a}" names sender "${f}", which no source declares`);return{plan:{product:n.product,events:t,commonProperties:r,sources:i,file:s},problems:o}}function Fe(e,n="plan"){let s=[],o=t=>s.push(`${n}: ${t}`);if(!$(e))return o("the plan must be a JSON object"),s;if(I(e,Ie,"the plan",o),(typeof e.product!="string"||!se.test(e.product))&&o('"product" must be a snake_case product slug'),e.extends!==void 0&&(typeof e.extends!="string"||e.extends.length===0)&&o(`"extends" must be "${ne}" or a path to another plan`),!$(e.events))o('"events" must be an object keyed by event name');else for(let[t,r]of Object.entries(e.events))Ke(t,r,o);if(e.commonProperties!==void 0&&ae("commonProperties",e.commonProperties,o),e.sources!==void 0)if(!Array.isArray(e.sources))o('"sources" must be an array');else for(let[t,r]of e.sources.entries())Be(r,t,o);return s}function Ke(e,n,s){if(D.test(e)||s(`event "${e}" is not a snake_case name`),!$(n)){s(`event "${e}" must be an object`);return}I(n,xe,`event "${e}"`,s),Object.keys(n).every(t=>oe.has(t))||((typeof n.description!="string"||n.description.trim()==="")&&s(`event "${e}" needs a description`),Q.includes(n.stage)||s(`event "${e}" stage must be one of ${Q.join(", ")}`),(typeof n.owner!="string"||n.owner.trim()==="")&&s(`event "${e}" needs an owner`),R.includes(n.personalData)||s(`event "${e}" personalData must be one of ${R.join(", ")}`)),n.senders!==void 0&&(!Array.isArray(n.senders)||n.senders.some(t=>typeof t!="string"))&&s(`event "${e}" senders must be an array of sender names`),n.properties!==void 0&&ae(`event "${e}"`,n.properties,s)}function ae(e,n,s){if(!$(n)){s(`${e} properties must be an object keyed by property name`);return}for(let[o,t]of Object.entries(n)){if(se.test(o)||s(`${e} property "${o}" is not a snake_case name`),!$(t)){s(`${e} property "${o}" must be an object`);continue}I(t,ke,`${e} property "${o}"`,s),X.includes(t.type)||s(`${e} property "${o}" type must be one of ${X.join(", ")}`),t.values!==void 0&&(!Array.isArray(t.values)||t.values.length===0)&&s(`${e} property "${o}" values must be a non-empty array`),t.nullable!==void 0&&typeof t.nullable!="boolean"&&s(`${e} property "${o}" nullable must be true or false`),t.personalData!==void 0&&!R.includes(t.personalData)&&s(`${e} property "${o}" personalData must be one of ${R.join(", ")}`)}}function Be(e,n,s){let o=`sources[${n}]`;if(!$(e)){s(`${o} must be an object`);return}I(e,je,o,s),(typeof e.sender!="string"||e.sender==="")&&s(`${o} needs a sender`),we.has(e.language)||s(`${o} language must be csharp or javascript`);for(let t of["constants","references","calls","ignoreConstants","scan","exclude"])e[t]!==void 0&&(!Array.isArray(e[t])||e[t].some(r=>typeof r!="string"))&&s(`${o} ${t} must be an array of strings`);Array.isArray(e.calls)&&e.calls.some(t=>typeof t=="string"&&!Le.test(t))&&s(`${o} calls must be function names, such as trackSiteEvent`),(e.constants?.length??0)===0&&((e.references?.length??0)>0||(e.calls?.length??0)===0)&&s(`${o} needs at least one constants file, unless it has calls and no references`)}function I(e,n,s,o){for(let t of Object.keys(e))n.has(t)||o(`${s} has an unknown field "${t}"`)}function $(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ce(e,n,s={}){if(typeof n=="string"&&n.startsWith("$"))return[];let o=e.events.get(n);if(!o)return[`event "${n}" is not in the ${e.product} tracking plan`];let t=[];for(let[r,i]of Object.entries(s??{})){if(r.startsWith("$"))continue;let c=o.properties.get(r)??e.commonProperties.get(r);if(!c){t.push(`event "${n}" sends property "${r}", which the plan does not declare`);continue}let a=Ge(c,i);a&&t.push(`event "${n}" property "${r}" ${a}`)}return t}function Ge(e,n){return n==null?e.nullable?null:"is null, and the plan does not mark it nullable":{string:typeof n=="string",integer:Number.isInteger(n),number:typeof n=="number"&&Number.isFinite(n),boolean:typeof n=="boolean",array:Array.isArray(n),object:$(n)}[e.type]?e.values&&!e.values.includes(n)?`is "${n}", which is not one of ${e.values.join(", ")}`:null:`is ${Array.isArray(n)?"array":typeof n}, but the plan declares ${e.type}`}var pe=`usage: webority-analytics-check-events --plan <tracking-plan.json> [--root <dir>] [--events <file.jsonl>]
|
|
9
|
-
|
|
10
|
-
${
|
|
11
|
-
`);for(let e of
|
|
12
|
-
`);process.exit(1)}var
|
|
13
|
-
`);for(let{file:e,line:n,message:
|
|
14
|
-
`);process.exit(1)}var
|
|
15
|
-
`);
|
|
2
|
+
import{readFileSync as qe}from"node:fs";import{resolve as ge}from"node:path";import{parseArgs as Ze}from"node:util";import{existsSync as V,readdirSync as $e,readFileSync as J}from"node:fs";import{basename as Pe,dirname as q,join as ve,relative as Z,resolve as j,sep as Ce}from"node:path";var f=Object.freeze({SIGNUP_STARTED:"signup_started",SIGNUP_COMPLETED:"signup_completed",LOGIN_SUCCEEDED:"login_succeeded",ONBOARDING_STARTED:"onboarding_started",ONBOARDING_STEP_COMPLETED:"onboarding_step_completed",ONBOARDING_COMPLETED:"onboarding_completed",SUBSCRIPTION_ACTIVATED:"subscription_activated",SUBSCRIPTION_CANCELLED:"subscription_cancelled",PAYMENT_SUCCEEDED:"payment_succeeded",PAYMENT_FAILED:"payment_failed",FEEDBACK_SUBMITTED:"feedback_submitted",LEAD_SUBMITTED:"lead_submitted",LEAD_QUALIFIED:"lead_qualified",LEAD_WON:"lead_won",WHATSAPP_CLICK:"whatsapp_click",CALCULATOR_USE:"calculator_use",PHONE_CLICK:"phone_click",DEMO_BOOKED:"demo_booked",CONTACT_SUBMITTED:"contact_submitted",TRIAL_START_CLICK:"trial_start_click",SAMPLE_REPORT_DOWNLOAD:"sample_report_download",REPORT_VERIFIED:"report_verified",CONTENT_ENGAGED:"content_engaged",EMAIL_CLICK:"email_click",PAGE_NOT_FOUND:"page_not_found",CHAT_OPENED:"chat_opened",CHAT_STARTED:"chat_started",CHAT_INPUT_SUBMITTED:"chat_input_submitted",CHAT_HANDOFF_REQUESTED:"chat_handoff_requested",CHAT_RATED:"chat_rated",CHAT_ACTION_REPEATED:"chat_action_repeated",TOUR_STARTED:"tour_started",TOUR_STEP_VIEWED:"tour_step_viewed",TOUR_COMPLETED:"tour_completed",TOUR_SKIPPED:"tour_skipped"}),sn=Object.freeze({signupStarted:f.SIGNUP_STARTED,signupCompleted:f.SIGNUP_COMPLETED,loginSucceeded:f.LOGIN_SUCCEEDED,onboardingStarted:f.ONBOARDING_STARTED,onboardingStepCompleted:f.ONBOARDING_STEP_COMPLETED,onboardingCompleted:f.ONBOARDING_COMPLETED,subscriptionActivated:f.SUBSCRIPTION_ACTIVATED,subscriptionCancelled:f.SUBSCRIPTION_CANCELLED,paymentSucceeded:f.PAYMENT_SUCCEEDED,paymentFailed:f.PAYMENT_FAILED,feedbackSubmitted:f.FEEDBACK_SUBMITTED,leadSubmitted:f.LEAD_SUBMITTED,leadQualified:f.LEAD_QUALIFIED,leadWon:f.LEAD_WON,whatsappClick:f.WHATSAPP_CLICK,calculatorUse:f.CALCULATOR_USE,phoneClick:f.PHONE_CLICK,demoBooked:f.DEMO_BOOKED,contactSubmitted:f.CONTACT_SUBMITTED,trialStartClick:f.TRIAL_START_CLICK,sampleReportDownload:f.SAMPLE_REPORT_DOWNLOAD,reportVerified:f.REPORT_VERIFIED,contentEngaged:f.CONTENT_ENGAGED,emailClick:f.EMAIL_CLICK,pageNotFound:f.PAGE_NOT_FOUND,chatOpened:f.CHAT_OPENED,chatStarted:f.CHAT_STARTED,chatInputSubmitted:f.CHAT_INPUT_SUBMITTED,chatHandoffRequested:f.CHAT_HANDOFF_REQUESTED,chatRated:f.CHAT_RATED,chatActionRepeated:f.CHAT_ACTION_REPEATED,tourStarted:f.TOUR_STARTED,tourStepViewed:f.TOUR_STEP_VIEWED,tourCompleted:f.TOUR_COMPLETED,tourSkipped:f.TOUR_SKIPPED}),R=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;var N={"(":")","[":"]","{":"}"},k=new Set([")","]","}"]),he=/[A-Za-z_$]/,ye=/[A-Za-z0-9_$]/;function G(e,n=new Map){let t=x(e,"csharp"),s=L(t),r=[],o=/\bconst\s+string\s+(\w+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([A-Za-z_][\w.]*))\s*;/g;for(let i of t.matchAll(o)){let a=i[2]??null;if(a===null){let c=(i[3]??"").split(".");a=c.length>=2&&c.at(-2)==="AnalyticsEvents"?n.get(c.at(-1)??"")??null:null}r.push({name:i[1]??"",value:a,line:s(i.index??0)})}return r}function K(e){let n=x(e,"javascript"),t=L(n),s=[],r=/([A-Za-z_$][\w$]*)\s*:\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)')/g;for(let o of n.matchAll(r))s.push({name:o[1]??"",value:o[2]??o[3]??null,line:t(o.index??0)});return s}function B(e,n,t){if(n.length===0)return[];let s=x(e,t),r=n.map(W).join("|"),o=new RegExp(`(?<![\\w$.])(?:${r})((?:\\.[A-Za-z_$][\\w$]*)+)`,"g"),i=L(s),a=[];for(let c of s.matchAll(o)){let l=c.index??0;if(Y(s,l,t))continue;let u=(c[1]??"").split(".").at(-1)??"",d=l+c[0].length;/^\s*\(/.test(s.slice(d,d+8))||a.push({constant:u,line:i(l),properties:z(s,d,t)})}return a}function H(e,n,t){if(n.length===0)return[];let s=x(e,t),r=n.map(W).join("|"),o=new RegExp(`(?<![\\w$])(${r})\\s*\\(`,"g"),i=L(s),a=[];for(let c of s.matchAll(o)){let l=c.index??0;if(Y(s,l,t))continue;let{names:u,end:d}=_e(s,l+c[0].length,t);if(u.length===0)continue;let E=z(s,d,t),_=i(l);for(let O of u)a.push({call:c[1]??"",name:O,line:_,properties:E})}return a}function _e(e,n,t){let s=[],r=n,o="(",i=0;for(let a=n;a<e.length;a++){let c=A(e,a,t);if(c!==a){if(i===0&&Se(e,a,c,t)){let u=e.slice(c).trimStart().charAt(0);((o==="("||o===":")&&(u===","||u===")")||o==="?"&&u===":")&&(s.push(e.slice(a+1,c-1)),r=c)}o="literal",a=c-1;continue}let l=e.charAt(a);if(!/\s/.test(l)){if(N[l])i++;else if(k.has(l)){if(i===0)break;i--}else if(i===0&&l===",")break;if(l==="?"&&(e[a+1]==="?"||e[a+1]===".")){o="operator",a++;continue}o=l}}return{names:s,end:r}}function Se(e,n,t,s){let r=e.charAt(n);return t-n<2||e.charAt(t-1)!==r?!1:r==="`"?!e.slice(n,t).includes("${"):s==="javascript"||r==='"'}function z(e,n,t){let s=0,r=null;for(let o=n;o<e.length;o++){let i=A(e,o,t);if(i!==o){o=i-1;continue}let a=e.charAt(o);if(s===0){if(a===";"||a==="="&&e[o+1]===">")break;if(a==="{"){let c=Ae(e,o,t),l=t==="csharp"?Te(e,o,c):be(e,o,c,t);l.length>0&&(r=[...r??[],...l]),o=c;continue}}if(N[a])s++;else if(k.has(a)){if(s===0)break;s--}}return r}function be(e,n,t,s){let r=[],o=!0,i=0;for(let a=n+1;a<t;a++){let c=A(e,a,s);if(c!==a){if(o&&i===0&&(e[a]==='"'||e[a]==="'")){let u=e.slice(a+1,c-1);/^\s*:/.test(e.slice(c,t))&&r.push(u)}o=!1,a=c-1;continue}let l=e.charAt(a);if(N[l]){i++,o=!1;continue}if(k.has(l)){i--;continue}if(!(i>0)){if(l===","){o=!0;continue}if(!(!o||/\s/.test(l))){if(he.test(l)){let u=a;for(;u<t&&ye.test(e.charAt(u));)u++;let d=e.slice(u,t).trimStart();(d.startsWith(":")||d.startsWith(",")||d==="")&&r.push(e.slice(a,u)),a=u-1}o=!1}}}return r}function Te(e,n,t){let s=e.slice(n,t+1),r=[];for(let o of s.matchAll(/\[\s*"((?:[^"\\]|\\.)*)"\s*\]\s*=(?!=)/g))r.push(o[1]??"");for(let o of s.matchAll(/\{\s*"((?:[^"\\]|\\.)*)"\s*,/g))(o.index??0)>0&&r.push(o[1]??"");return r}function Ae(e,n,t){let s=0;for(let r=n;r<e.length;r++){let o=A(e,r,t);if(o!==r){r=o-1;continue}let i=e.charAt(r);if(N[i])s++;else if(k.has(i)&&--s===0)return r}return e.length-1}function A(e,n,t){let s=e.charAt(n);if(t==="csharp"&&s==="@"&&e.charAt(n+1)==='"'){let o=n+2;for(;o<e.length;){if(e[o]==='"'&&e[o+1]==='"'){o+=2;continue}if(e[o]==='"')return o+1;o++}return e.length}if(s!=='"'&&s!=="'"&&!(s==="`"&&t==="javascript"))return n;let r=n+1;for(;r<e.length&&e[r]!==s;){if(e[r]==="\\")r++;else if(e[r]===`
|
|
3
|
+
`&&s!=="`")return r;r++}return r+1}function Y(e,n,t){let s=e.lastIndexOf(`
|
|
4
|
+
`,n)+1;for(let r=s;r<n;r++){let o=A(e,r,t);if(o!==r){if(o>n)return!0;r=o-1}}return!1}function x(e,n){let t=e.replace(/\r\n?/g,`
|
|
5
|
+
`),s="";for(let r=0;r<t.length;r++){let o=A(t,r,n);if(o!==r){s+=t.slice(r,o),r=o-1;continue}if(t[r]==="/"&&t[r+1]==="/"){let i=t.indexOf(`
|
|
6
|
+
`,r),a=i===-1?t.length:i;s+=" ".repeat(a-r),r=a-1;continue}if(t[r]==="/"&&t[r+1]==="*"){let i=t.indexOf("*/",r+2),a=i===-1?t.length:i+2;s+=t.slice(r,a).replace(/[^\n]/g," "),r=a-1;continue}s+=t.charAt(r)}return s}function L(e){let n=[];for(let t=e.indexOf(`
|
|
7
|
+
`);t!==-1;t=e.indexOf(`
|
|
8
|
+
`,t+1))n.push(t);return t=>{let s=0,r=n.length;for(;s<r;){let o=s+r>>>1;(n[o]??0)<t?s=o+1:r=o}return s+1}}function W(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var De={csharp:new Set([".cs"]),javascript:new Set([".js",".jsx",".mjs",".cjs",".ts",".tsx",".html",".cshtml",".razor"])},Oe="trackSiteEvent",Re=/^(node_modules|bin|obj|dist|build|coverage|\.git|\.expo|__tests__|__mocks__|tests?)$|\.Tests?$/i,Ne=/\.(test|spec)\.[cm]?[jt]sx?$|\.d\.ts$/i;function ke(e){let n=new Map;for(let[t,s]of e.events)s.origin==="fleet"&&n.set(Le(t),t);return n}function Q(e,n){let t=[],s=(i,a,c)=>t.push({file:i?ne(Z(n,i)):null,line:a,message:c}),r=ke(e),o={constants:0,callSites:0,files:0};for(let i of e.sources){let a=new Map,c=new Set(i.ignoreConstants??[]),l=new Set;for(let S of i.constants??[]){let m=j(n,S);if(l.add(m),!V(m)){s(null,null,`${i.sender}: constants file ${S} does not exist`);continue}let g=J(m,"utf8"),T=i.language==="csharp"?G(g,r):K(g);for(let p of T){if(c.has(p.name))continue;if(o.constants++,p.value===null){s(m,p.line,`${p.name} is not a string literal or an AnalyticsEvents constant, so its event name cannot be read`);continue}if(!R.test(p.value)){s(m,p.line,`${p.name} = "${p.value}" is not a snake_case event name (list it in ignoreConstants if it is not an event)`);continue}e.events.has(p.value)||s(m,p.line,`event "${p.value}" (${p.name}) is not in the ${e.product} tracking plan`);let h=a.get(p.name);h!==void 0&&h!==p.value&&s(m,p.line,`${p.name} is declared twice with different events ("${h}" and "${p.value}")`),a.set(p.name,p.value)}}let u=i.references??[],d=i.language==="csharp",E=d?[...new Set([...u,"AnalyticsEvents"])]:u,_=i.language==="javascript"?[...new Set([...i.calls??[],Oe])]:i.calls??[];if(E.length===0&&_.length===0)continue;let O=(S,m,g,T)=>{let p=e.events.get(g);if(p){p.senders.includes(i.sender)||s(S,m,`event "${g}" is sent by ${i.sender}, which its plan entry does not list as a sender`);for(let h of T??[])!p.properties.has(h)&&!e.commonProperties.has(h)&&s(S,m,`event "${g}" sends property "${h}", which the plan does not declare`)}};for(let S of i.scan??[]){let m=j(n,S);if(!V(m)){s(null,null,`${i.sender}: scan folder ${S} does not exist`);continue}for(let g of X(m,De[i.language],i.exclude??[],n)){if(l.has(g))continue;o.files++;let T=J(g,"utf8");for(let p of B(T,E,i.language)){if(c.has(p.constant))continue;let h=a.get(p.constant)??(d?r.get(p.constant):void 0);if(h===void 0){if(i.language==="javascript"){if(i.constants===void 0)throw new Error(`catalogue check: the JavaScript source for ${g} names no constants list; plan validation should have refused it.`);s(g,p.line,`${p.constant} is not an event constant in ${i.constants.join(", ")}`)}continue}o.callSites++,O(g,p.line,h,p.properties)}for(let p of H(T,_,i.language)){if(o.callSites++,!e.events.has(p.name)){s(g,p.line,`event "${p.name}" (sent through ${p.call}) is not in the ${e.product} tracking plan`);continue}O(g,p.line,p.name,p.properties)}}}}return{problems:t,summary:o}}function*X(e,n,t,s){let r=$e(e,{withFileTypes:!0}).sort((o,i)=>o.name<i.name?-1:o.name>i.name?1:0);for(let o of r){let i=ve(e,o.name),a=ne(Z(s,i));t.some(c=>a===c||a.startsWith(`${c}/`)||o.name===c)||(o.isDirectory()?Re.test(o.name)||(yield*X(i,n,t,s)):o.isFile()&&n.has(xe(o.name))&&!Ne.test(o.name)&&(yield i))}}function xe(e){let n=e.lastIndexOf(".");return n===-1?"":e.slice(n).toLowerCase()}function ee(e){let n=q(j(e));return Pe(n)===".webority"?q(n):n}function Le(e){return e.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function ne(e){return e.split(Ce).join("/")}import{readFileSync as Ie}from"node:fs";import{dirname as we,resolve as oe}from"node:path";var ie="@webority/analytics/fleet",te=Object.freeze(["acquisition","activation","engagement","retention","revenue","referral","support","quality"]),I=Object.freeze(["none","pseudonymous","personal"]),se=Object.freeze(["string","integer","number","boolean","array","object"]),ae=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,je=Object.freeze(["csharp","javascript"]),ce=new Set(["properties","senders"]),Me=new Set(["$schema","product","extends","description","commonProperties","events","sources"]),Ue=new Set(["description","stage","owner","personalData","senders","properties"]),Fe=new Set(["type","description","values","nullable","personalData"]),Ge=new Set(["sender","language","constants","references","calls","ignoreConstants","scan","exclude"]),Ke=/^[A-Za-z_$][\w$]*$/,re=4,Be=new URL("./fleet-tracking-plan.json",import.meta.url);function le(e){return pe(oe(e),0)}function pe(e,n){let t=typeof e=="string"?e:"fleet-tracking-plan.json",s;try{s=JSON.parse(Ie(e,"utf8"))}catch(i){return{plan:null,problems:[`${t}: cannot read the plan (${Ve(i)})`]}}if(!We(s,t))return{plan:null,problems:ue(s,t)};let r=null;if(s.extends!==void 0){if(n>=re)return{plan:null,problems:[`${t}: "extends" is nested more than ${re} deep`]};let i=s.extends===ie?Be:oe(we(String(e)),s.extends),a=pe(i,n+1);if(!a.plan)return{plan:null,problems:a.problems};r=a.plan}let o=He(r,s,t);return{plan:o.plan,problems:o.problems}}function He(e,n,t="plan"){let s=[],r=new Map,o=new Map(e?.commonProperties);if(e)for(let[c,l]of e.events)r.set(c,{...l,properties:new Map(l.properties),senders:[...l.senders]});for(let[c,l]of Object.entries(n.commonProperties??{})){let u=o.get(c);if(u&&u.type!==l.type){s.push(`${t}: common property "${c}" is ${l.type} here but ${u.type} in the base plan`);continue}o.set(c,{...l,origin:u?.origin??n.product})}for(let[c,l]of Object.entries(n.events??{})){let u=r.get(c);if(!u){let d=["description","stage","owner","personalData"].filter(E=>l[E]===void 0);d.length>0&&s.push(`${t}: event "${c}" is not in the base plan, so it needs description, stage, owner and personalData (missing ${d.join(", ")})`),r.set(c,{name:c,description:l.description,stage:l.stage,owner:l.owner,personalData:l.personalData,senders:[...l.senders??[]],properties:new Map(Object.entries(l.properties??{})),origin:n.product});continue}for(let d of Object.keys(l))ce.has(d)||s.push(`${t}: event "${c}" is defined by the base plan, so it may only add properties or senders (found "${d}")`);for(let d of l.senders??[])u.senders.includes(d)||u.senders.push(d);for(let[d,E]of Object.entries(l.properties??{})){let _=u.properties.get(d);if(_&&_.type!==E.type){s.push(`${t}: "${c}.${d}" is ${E.type} here but ${_.type} in the base plan`);continue}u.properties.set(d,E)}}for(let[c,l]of r)for(let u of l.properties.keys())o.has(u)&&s.push(`${t}: "${c}.${u}" is already a common property, so it must not be declared on the event`);let i=n.sources??[],a=new Set(i.map(c=>c.sender));if(i.length>0)for(let[c,l]of Object.entries(n.events??{}))for(let u of l.senders??[])a.has(u)||s.push(`${t}: event "${c}" names sender "${u}", which no source declares`);return{plan:{product:n.product,events:r,commonProperties:o,sources:i,file:t},problems:s}}function ue(e,n="plan"){let t=[],s=r=>{t.push(`${n}: ${r}`)};if(!b(e))return s("the plan must be a JSON object"),t;if(w(e,Me,"the plan",s),(typeof e.product!="string"||!ae.test(e.product))&&s('"product" must be a snake_case product slug'),e.extends!==void 0&&(typeof e.extends!="string"||e.extends.length===0)&&s(`"extends" must be "${ie}" or a path to another plan`),!b(e.events))s('"events" must be an object keyed by event name');else for(let[r,o]of Object.entries(e.events))ze(r,o,s);if(e.commonProperties!==void 0&&fe("commonProperties",e.commonProperties,s),e.sources!==void 0)if(!$(e.sources))s('"sources" must be an array');else for(let[r,o]of e.sources.entries())Ye(o,r,s);return t}function ze(e,n,t){if(R.test(e)||t(`event "${e}" is not a snake_case name`),!b(n)){t(`event "${e}" must be an object`);return}w(n,Ue,`event "${e}"`,t),Object.keys(n).every(r=>ce.has(r))||((typeof n.description!="string"||n.description.trim()==="")&&t(`event "${e}" needs a description`),v(te,n.stage)||t(`event "${e}" stage must be one of ${te.join(", ")}`),(typeof n.owner!="string"||n.owner.trim()==="")&&t(`event "${e}" needs an owner`),v(I,n.personalData)||t(`event "${e}" personalData must be one of ${I.join(", ")}`)),n.senders!==void 0&&(!$(n.senders)||n.senders.some(r=>typeof r!="string"))&&t(`event "${e}" senders must be an array of sender names`),n.properties!==void 0&&fe(`event "${e}"`,n.properties,t)}function fe(e,n,t){if(!b(n)){t(`${e} properties must be an object keyed by property name`);return}for(let[s,r]of Object.entries(n)){if(ae.test(s)||t(`${e} property "${s}" is not a snake_case name`),!b(r)){t(`${e} property "${s}" must be an object`);continue}w(r,Fe,`${e} property "${s}"`,t),v(se,r.type)||t(`${e} property "${s}" type must be one of ${se.join(", ")}`),r.values!==void 0&&(!$(r.values)||r.values.length===0)&&t(`${e} property "${s}" values must be a non-empty array`),r.nullable!==void 0&&typeof r.nullable!="boolean"&&t(`${e} property "${s}" nullable must be true or false`),r.personalData!==void 0&&!v(I,r.personalData)&&t(`${e} property "${s}" personalData must be one of ${I.join(", ")}`)}}function Ye(e,n,t){let s=`sources[${n}]`;if(!b(e)){t(`${s} must be an object`);return}w(e,Ge,s,t),(typeof e.sender!="string"||e.sender==="")&&t(`${s} needs a sender`),v(je,e.language)||t(`${s} language must be csharp or javascript`);for(let o of["constants","references","calls","ignoreConstants","scan","exclude"]){let i=e[o];i!==void 0&&(!$(i)||i.some(a=>typeof a!="string"))&&t(`${s} ${o} must be an array of strings`)}let r=e.calls;$(r)&&r.some(o=>typeof o=="string"&&!Ke.test(o))&&t(`${s} calls must be function names, such as trackSiteEvent`),M(e.constants)===0&&(M(e.references)>0||M(e.calls)===0)&&t(`${s} needs at least one constants file, unless it has calls and no references`)}function M(e){return $(e)||typeof e=="string"?e.length:0}function w(e,n,t,s){for(let r of Object.keys(e))n.has(r)||s(`${t} has an unknown field "${r}"`)}function We(e,n){return ue(e,n).length===0}function b(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function $(e){return Array.isArray(e)}function v(e,n){return e.some(t=>t===n)}function Ve(e){return e instanceof Error?e.message:String(e)}function de(e,n,t={}){if(typeof n=="string"&&n.startsWith("$"))return[];let s=typeof n=="string"?e.events.get(n):void 0;if(!s)return[`event "${n}" is not in the ${e.product} tracking plan`];let r=[],o=Object.entries(t??{});for(let[i,a]of o){if(i.startsWith("$"))continue;let c=s.properties.get(i)??e.commonProperties.get(i);if(!c){r.push(`event "${n}" sends property "${i}", which the plan does not declare`);continue}let l=Je(c,a);l&&r.push(`event "${n}" property "${i}" ${l}`)}return r}function Je(e,n){return n==null?e.nullable?null:"is null, and the plan does not mark it nullable":{string:typeof n=="string",integer:Number.isInteger(n),number:typeof n=="number"&&Number.isFinite(n),boolean:typeof n=="boolean",array:Array.isArray(n),object:b(n)}[e.type]?e.values&&!e.values.includes(n)?`is "${n}", which is not one of ${e.values.join(", ")}`:null:`is ${Array.isArray(n)?"array":typeof n}, but the plan declares ${e.type}`}var me=`usage: webority-analytics-check-events --plan <tracking-plan.json> [--root <dir>] [--events <file.jsonl>]
|
|
9
|
+
`;function Qe(){try{return Ze({options:{plan:{type:"string"},root:{type:"string"},events:{type:"string"},help:{type:"boolean"}}}).values}catch(e){process.stderr.write(`${e instanceof Error?e.message:String(e)}
|
|
10
|
+
${me}`),process.exit(2)}}var y=Qe();(y.help||!y.plan)&&((y.help?process.stdout:process.stderr).write(me),process.exit(y.help?0:2));var{plan:P,problems:U}=le(y.plan);if(!P||U.length>0){process.stderr.write(`The tracking plan has ${U.length} problem(s):
|
|
11
|
+
`);for(let e of U)process.stderr.write(` ${e}
|
|
12
|
+
`);process.exit(1)}var Xe=ge(y.root??ee(y.plan)),{problems:D,summary:F}=Q(P,Xe),C=y.events,Ee=0;C&&qe(ge(C),"utf8").split(/\r?\n/).forEach((n,t)=>{if(n.trim()==="")return;let s=nn(n);if(s===null){D.push({file:C,line:t+1,message:"not a JSON object"});return}Ee++;for(let r of de(P,s.event,s.properties))D.push({file:C,line:t+1,message:r})});if(D.length>0){process.stderr.write(`${D.length} event problem(s) against the ${P.product} tracking plan (${y.plan}):
|
|
13
|
+
`);for(let{file:e,line:n,message:t}of D)process.stderr.write(` ${e?`${e}${n?`:${n}`:""}: `:""}${t}
|
|
14
|
+
`);process.exit(1)}var en=C?`, ${Ee} captured event(s)`:"";process.stdout.write(`OK: ${P.events.size} events in the ${P.product} plan; ${F.constants} constants and ${F.callSites} call sites in ${F.files} files${en} all match.
|
|
15
|
+
`);function nn(e){let n;try{n=JSON.parse(e)}catch{return null}return tn(n)?n:null}function tn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as et}from"./chunk-S6QAWBSZ.js";var xt=["google","googleads","adwords","youtube"],Ft=["meta","facebook","fb","instagram","ig","messenger"],Ut=["linkedin","lnkd"],Mt=["bing","microsoft","microsoftads","msn"],nt=Object.freeze([["chatgpt",["chatgpt.com","chat.openai.com"]],["perplexity",["perplexity.ai"]],["gemini",["gemini.google.com"]],["copilot",["copilot.microsoft.com"]],["claude",["claude.ai"]],["you",["you.com"]],["phind",["phind.com"]],["deepseek",["deepseek.com"]],["grok",["grok.com"]],["meta_ai",["meta.ai"]],["poe",["poe.com"]]]),Ht=["bing.com","duckduckgo.com","search.yahoo.com","ecosia.org","search.brave.com"],Vt=["google","yandex"],$t=["facebook.com","fb.com","instagram.com","linkedin.com","lnkd.in","twitter.com","t.co","x.com","reddit.com","pinterest.com","youtube.com","youtu.be","tiktok.com","whatsapp.com","threads.net","t.me","telegram.org"],g=Object.freeze({DIRECT:"direct",GOOGLE:"google",META:"meta",LINKEDIN:"linkedin",MICROSOFT:"microsoft",OTHER:"other",AI_ASSISTANT:"ai_assistant",ORGANIC_SEARCH:"organic_search",ORGANIC_SOCIAL:"organic_social",REFERRAL:"referral"});function A(t){if(!t)return g.DIRECT;let e=m(t.utmSource);if(e){let r=O(e);if(xt.includes(r))return g.GOOGLE;if(Ft.includes(r))return g.META;if(Ut.includes(r))return g.LINKEDIN;if(Mt.includes(r))return g.MICROSOFT}if(m(t.fbclid))return g.META;if(m(t.gclid)||m(t.gbraid)||m(t.wbraid))return g.GOOGLE;if(m(t.liFatId))return g.LINKEDIN;if(m(t.msclkid))return g.MICROSOFT;if(ot(e))return g.AI_ASSISTANT;if(e||m(t.utmMedium)||m(t.utmCampaign)||m(t.utmContent)||m(t.utmTerm))return g.OTHER;let o=st(t.referrer);return o?rt(o)?g.AI_ASSISTANT:Gt(o)?g.ORGANIC_SEARCH:$t.some(r=>it(o,r))?g.ORGANIC_SOCIAL:g.REFERRAL:g.DIRECT}function F(t){if(!t)return"";let e=ot(m(t.utmSource));if(e)return e;let n=st(t.referrer);return n?rt(n):""}function ot(t){if(!t)return"";let e=O(t);for(let[n,o]of nt){let r=o;if(O(n)===e||r.some(i=>O(i)===e))return n}return""}function rt(t){for(let[e,n]of nt)if(n.some(r=>it(t,r)))return e;return""}function Gt(t){return Ht.includes(t)?!0:Vt.some(e=>{if(!t.startsWith(`${e}.`))return!1;let n=t.slice(e.length+1).split(".");return n.length===1||n.length===2&&(n[0]==="co"||n[0]==="com")})}function it(t,e){return t===e||t.endsWith(`.${e}`)}function st(t){let e=m(t);if(!e)return"";try{let n=new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:`https://${e}`).hostname.toLowerCase();return n.startsWith("www.")?n.slice(4):n}catch{return""}}function O(t){return String(t).toLowerCase().replace(/[^\p{L}\p{N}]/gu,"")}function m(t){return String(t??"").trim()}var U=Object.freeze(["AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IE","IT","LV","LT","LU","MT","NL","PL","PT","RO","SK","SI","ES","SE","IS","LI","NO","GB","CH"]);function Wt(t){return U.some(e=>e===t)}function qt(t){let e=typeof t=="string"?t.trim().toUpperCase():"";return e.length!==2||e==="XX"||e==="T1"?!0:Wt(e)}var v="webority_cookie_consent",ct="webority-consent-change",ut=365,Bt=["eea","other"],M=new Set,a={initialized:!1,requiresOptIn:!0,strictOptIn:!1,adStorage:!0,cookieDays:ut,cookieDomain:null,regionCookie:null,region:null,saved:null};function zt(t){let e=t?.strictOptIn??!1;if(typeof e!="boolean")throw new Error("@webority/analytics: initConsent strictOptIn must be true or false, or left out.");if(e){if(t.requiresOptIn!==void 0&&t.requiresOptIn!==!0)throw new Error("@webority/analytics: initConsent strictOptIn asks every visitor to opt in, so requiresOptIn must be true or left out.")}else if(typeof t?.requiresOptIn!="boolean")throw new Error("@webority/analytics: initConsent needs requiresOptIn (true or false), decided from the visitor's country.");if(t.cookieDomain!==void 0&&(typeof t.cookieDomain!="string"||!t.cookieDomain.trim()))throw new Error('@webority/analytics: initConsent cookieDomain must be a domain such as ".example.com", or left out.');if(t.cookieDays!==void 0&&!(Number.isInteger(t.cookieDays)&&t.cookieDays>0))throw new Error("@webority/analytics: initConsent cookieDays must be a whole number of days above zero, or left out.");if(t.adStorage!==void 0&&typeof t.adStorage!="boolean")throw new Error("@webority/analytics: initConsent adStorage must be true or false, or left out.");if(t.regionCookie!==void 0&&(typeof t.regionCookie!="string"||!/^[\w.-]+$/.test(t.regionCookie)))throw new Error('@webority/analytics: initConsent regionCookie must be a cookie name such as "wui_region", or left out.');a.initialized=!0,a.strictOptIn=e,a.requiresOptIn=e||t.requiresOptIn===!0,a.adStorage=t.adStorage??!e,a.cookieDays=t.cookieDays??ut,a.cookieDomain=t.cookieDomain?.trim()??null,a.regionCookie=t.regionCookie??null,a.region=a.regionCookie?Jt(a.regionCookie):null;let{saved:n,entryCount:o}=Xt();a.saved=n,a.cookieDomain&&o>1&&n&&mt(n),Yt(),Qt(),a.saved?$(a.saved):ft()&>()}function Kt(t){if(V("setConsentRegion"),!pt(t))throw new Error('@webority/analytics: setConsentRegion needs "eea" or "other".');let e=f();if(a.region=t,a.saved)return;let n=f();e.analytics===n.analytics&&e.functional===n.functional&&e.marketing===n.marketing||(gt(),dt(n))}function C(){return a.initialized}function lt(){return a.strictOptIn}function H(){return a.adStorage}function f(){V("getConsent");let t=a.saved;if(t)return{essential:!0,analytics:t.analytics,functional:t.functional,marketing:t.marketing,decided:!0};if(ft())return{essential:!0,analytics:!0,functional:!0,marketing:!1,decided:!1};let e=!a.requiresOptIn;return{essential:!0,analytics:e,functional:e,marketing:e,decided:!1}}function jt(t){V("saveConsent");let e={essential:!0,analytics:t?.analytics===!0,functional:t?.functional===!0,marketing:t?.marketing===!0,timestamp:new Date().toISOString()};mt(e),a.saved=e,$(e),dt(f())}function E(t){return M.add(t),()=>M.delete(t)}function dt(t){for(let e of M)try{e(t)}catch(n){queueMicrotask(()=>{throw n})}typeof window?.dispatchEvent=="function"&&typeof CustomEvent=="function"&&window.dispatchEvent(new CustomEvent(ct,{detail:t}))}function V(t){if(!a.initialized)throw new Error(`@webority/analytics: call initConsent before ${t}.`)}function h(...t){window.dataLayer=window.dataLayer||[],window.dataLayer.push(arguments)}function Yt(){if(a.strictOptIn){h("consent","default",{ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied",functionality_storage:"denied",personalization_storage:"denied",security_storage:"granted",wait_for_update:500});return}h("consent","default",{ad_storage:"denied",ad_user_data:"denied",ad_personalization:"denied",analytics_storage:"denied",functionality_storage:"denied",personalization_storage:"denied",security_storage:"granted",wait_for_update:500,region:[...U]});let t=a.adStorage?"granted":"denied";h("consent","default",{ad_storage:t,ad_user_data:t,ad_personalization:t,analytics_storage:"granted",functionality_storage:"granted",personalization_storage:"granted",security_storage:"granted"})}function Qt(){h("set","ads_data_redaction",!0),h("set","url_passthrough",!0)}function ft(){return a.requiresOptIn&&!a.strictOptIn&&a.region==="other"}function gt(){let t=f();$(t,t.analytics&&a.adStorage)}function $(t,e=t.marketing&&a.adStorage){let n=o=>o?"granted":"denied";h("consent","update",{analytics_storage:n(t.analytics),functionality_storage:n(t.functional),personalization_storage:n(t.functional),ad_storage:n(e),ad_user_data:n(e),ad_personalization:n(e)})}function Xt(){let t=`${v}=`,e=(document.cookie||"").split(";").map(o=>o.trim()).filter(o=>o.startsWith(t)),n=e.map(o=>Zt(o.slice(t.length))).filter(o=>o!==null);return{saved:te(n),entryCount:e.length}}function Jt(t){let e=`${t}=`,o=(document.cookie||"").split(";").map(r=>r.trim()).find(r=>r.startsWith(e))?.slice(e.length);return pt(o)?o:null}function pt(t){return Bt.some(e=>e===t)}function Zt(t){try{let e=JSON.parse(decodeURIComponent(t));return ee(e)?{essential:!0,analytics:e.analytics===!0,functional:e.functional===!0,marketing:e.marketing===!0,timestamp:e.timestamp??null}:null}catch{return null}}function te(t){let e=t.map(i=>({choice:i,time:typeof i.timestamp=="string"?Date.parse(i.timestamp):Number.NaN}));if(e.some(i=>Number.isNaN(i.time)))return t.at(-1)??null;let[n,...o]=e;if(!n)return null;let r=n;for(let i of o)i.time>=r.time&&(r=i);return r.choice}function mt(t){let e=typeof t.timestamp=="string"?Date.parse(t.timestamp):Number.NaN,n=(Number.isNaN(e)?Date.now():e)+a.cookieDays*24*60*60*1e3,o=window.location?.protocol==="https:"?";Secure":"";a.cookieDomain&&at(`${v}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;max-age=0;path=/;SameSite=Lax${o}`);let r=a.cookieDomain?`;domain=${a.cookieDomain}`:"";at(`${v}=${encodeURIComponent(JSON.stringify(t))};expires=${new Date(n).toUTCString()};path=/${r};SameSite=Lax${o}`)}function at(t){document.cookie=t}function ee(t){return typeof t=="object"&&t!==null}var k="webority_attribution",ne=2160*60*60*1e3,oe=200,G=500,re=Object.freeze({utm_source:"utmSource",utm_medium:"utmMedium",utm_campaign:"utmCampaign",utm_content:"utmContent",utm_term:"utmTerm",gclid:"gclid",gbraid:"gbraid",wbraid:"wbraid",fbclid:"fbclid",msclkid:"msclkid",li_fat_id:"liFatId"}),ie=["utmSource","utmMedium","utmCampaign","utmContent","utmTerm","gclid","gbraid","wbraid","fbclid","msclkid","liFatId","referrer","aiSource","landingPage"],yt=!1;function se(){St("captureAttribution"),le();let t=ce();if(!t)return;let e=K(W());Ct(W(),{firstTouch:e?.firstTouch??t,lastTouch:t}),ae(t)}function ae(t){let e={event:"acquisition_touch",acquisition_channel:A(t)};t.aiSource&&(e.ai_source=t.aiSource),window.dataLayer=window.dataLayer||[],window.dataLayer.push(e)}function z(){return St("getAttribution"),K(W())}function ce(){let t=new URLSearchParams(window.location.search),e={};for(let[r,i]of Object.entries(re)){let c=R(t.get(r),oe);c&&(e[i]=c)}let n=R(t.get("referrer"),G)||ue();if(n&&(e.referrer=n),Object.keys(e).length===0)return null;let o=F(e);return o&&(e.aiSource=o),{...e,landingPage:R(window.location.pathname,G),capturedDateTimeUtc:new Date().toISOString()}}function ue(){let t=document.referrer;if(!t)return"";try{return new URL(t).hostname===window.location.hostname?"":R(t,G)}catch{return""}}function le(){yt||(yt=!0,E(t=>{let e=t.marketing?B():q(),n=t.marketing?q():B(),o=K(e);de(e),o&&Ct(n,o)}))}function W(){return f().marketing?q():B()}function q(){try{return window.localStorage}catch{return null}}function B(){try{return window.sessionStorage}catch{return null}}function K(t){try{let e=t?.getItem(k);if(!e)return null;let n=JSON.parse(e),o=Et(n)?n:{},r=_t(o.firstTouch),i=_t(o.lastTouch),c=r??i,d=i??r;return!c||!d?(t?.removeItem(k),null):{firstTouch:c,lastTouch:d}}catch{return null}}function Ct(t,e){try{t?.setItem(k,JSON.stringify(e))}catch{}}function de(t){try{t?.removeItem(k)}catch{}}function _t(t){if(!fe(t))return null;let e=Date.parse(t.capturedDateTimeUtc);return Number.isFinite(e)&&Date.now()-e<=ne?t:null}function fe(t){return!Et(t)||typeof t.capturedDateTimeUtc!="string"?!1:ie.every(e=>t[e]===void 0||typeof t[e]=="string")}function Et(t){return typeof t=="object"&&t!==null}function R(t,e){let n=String(t??"").trim();return n?n.slice(0,e):""}function St(t){if(!C())throw new Error(`@webority/analytics: call initConsent before ${t}.`)}function bt(t,e){return import("./web-vitals-ET2TNTYN.js").then(n=>n.startWebVitals(t,e)).catch(()=>{})}var ge=["scroll","mousemove","touchstart","keydown","pointerdown"];function N(t){let e=!1,n=()=>{e||(e=!0,t())};for(let o of ge)window.addEventListener(o,n,{once:!0,passive:!0});document.readyState==="complete"?setTimeout(n,1500):window.addEventListener("load",()=>setTimeout(n,1500),{once:!0})}var s=Object.freeze({SIGNUP_STARTED:"signup_started",SIGNUP_COMPLETED:"signup_completed",LOGIN_SUCCEEDED:"login_succeeded",ONBOARDING_STARTED:"onboarding_started",ONBOARDING_STEP_COMPLETED:"onboarding_step_completed",ONBOARDING_COMPLETED:"onboarding_completed",SUBSCRIPTION_ACTIVATED:"subscription_activated",SUBSCRIPTION_CANCELLED:"subscription_cancelled",PAYMENT_SUCCEEDED:"payment_succeeded",PAYMENT_FAILED:"payment_failed",FEEDBACK_SUBMITTED:"feedback_submitted",LEAD_SUBMITTED:"lead_submitted",LEAD_QUALIFIED:"lead_qualified",LEAD_WON:"lead_won",WHATSAPP_CLICK:"whatsapp_click",CALCULATOR_USE:"calculator_use",PHONE_CLICK:"phone_click",DEMO_BOOKED:"demo_booked",CONTACT_SUBMITTED:"contact_submitted",TRIAL_START_CLICK:"trial_start_click",SAMPLE_REPORT_DOWNLOAD:"sample_report_download",REPORT_VERIFIED:"report_verified",CONTENT_ENGAGED:"content_engaged",EMAIL_CLICK:"email_click",PAGE_NOT_FOUND:"page_not_found",CHAT_OPENED:"chat_opened",CHAT_STARTED:"chat_started",CHAT_INPUT_SUBMITTED:"chat_input_submitted",CHAT_HANDOFF_REQUESTED:"chat_handoff_requested",CHAT_RATED:"chat_rated",CHAT_ACTION_REPEATED:"chat_action_repeated",TOUR_STARTED:"tour_started",TOUR_STEP_VIEWED:"tour_step_viewed",TOUR_COMPLETED:"tour_completed",TOUR_SKIPPED:"tour_skipped"}),Ye=Object.freeze({signupStarted:s.SIGNUP_STARTED,signupCompleted:s.SIGNUP_COMPLETED,loginSucceeded:s.LOGIN_SUCCEEDED,onboardingStarted:s.ONBOARDING_STARTED,onboardingStepCompleted:s.ONBOARDING_STEP_COMPLETED,onboardingCompleted:s.ONBOARDING_COMPLETED,subscriptionActivated:s.SUBSCRIPTION_ACTIVATED,subscriptionCancelled:s.SUBSCRIPTION_CANCELLED,paymentSucceeded:s.PAYMENT_SUCCEEDED,paymentFailed:s.PAYMENT_FAILED,feedbackSubmitted:s.FEEDBACK_SUBMITTED,leadSubmitted:s.LEAD_SUBMITTED,leadQualified:s.LEAD_QUALIFIED,leadWon:s.LEAD_WON,whatsappClick:s.WHATSAPP_CLICK,calculatorUse:s.CALCULATOR_USE,phoneClick:s.PHONE_CLICK,demoBooked:s.DEMO_BOOKED,contactSubmitted:s.CONTACT_SUBMITTED,trialStartClick:s.TRIAL_START_CLICK,sampleReportDownload:s.SAMPLE_REPORT_DOWNLOAD,reportVerified:s.REPORT_VERIFIED,contentEngaged:s.CONTENT_ENGAGED,emailClick:s.EMAIL_CLICK,pageNotFound:s.PAGE_NOT_FOUND,chatOpened:s.CHAT_OPENED,chatStarted:s.CHAT_STARTED,chatInputSubmitted:s.CHAT_INPUT_SUBMITTED,chatHandoffRequested:s.CHAT_HANDOFF_REQUESTED,chatRated:s.CHAT_RATED,chatActionRepeated:s.CHAT_ACTION_REPEATED,tourStarted:s.TOUR_STARTED,tourStepViewed:s.TOUR_STEP_VIEWED,tourCompleted:s.TOUR_COMPLETED,tourSkipped:s.TOUR_SKIPPED}),ht=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;function Tt(){let t=new Set(Object.values(s));return{register(e){for(let n of e){if(!ht.test(n))throw new Error(`@webority/analytics: invalid event name "${n}". Expected snake_case.`);t.add(n)}},assertRegistered(e){if(!t.has(e))throw new Error(`@webority/analytics: event "${e}" is not registered. Call registerEvents() first.`)}}}var j=Tt(),u={config:null,posthogInstance:null,posthogInitPromise:null,pendingIdentify:null};function en(t){u.config=t,u.posthogInstance=null,u.posthogInitPromise=null,u.pendingIdentify=null}function pe(){let t=u.config;return t?!!(t.enabled&&t.clientKey&&t.environment!=="Local"):!1}function D(){return C()&&f().analytics}function wt(){return pe()&&D()}var P=new Set,It=new WeakSet,At=null;function rn(t){let e=Y();if(!e)return!1;try{return e.isFeatureEnabled(t)===!0}catch(n){return Rt(`feature flag "${t}" could not be read, so it reads as off`,n),L(n),!1}}function sn(t){let e=Y();if(!e)return null;try{return e.getFeatureFlag(t)??null}catch(n){return Rt(`feature flag "${t}" could not be read, so it reads as null`,n),L(n),null}}function an(t){P.add(t);let e=Y();return(!e||At===e)&&queueMicrotask(()=>{P.has(t)&&vt(t)}),()=>P.delete(t)}function Ot(t){u.config?.featureFlags!==!0||It.has(t)||typeof t.onFeatureFlags!="function"||(It.add(t),t.onFeatureFlags(()=>{At=t;for(let e of[...P])vt(e)}))}function Y(){return u.config?.featureFlags!==!0||!wt()?null:u.posthogInstance??null}function vt(t){try{t()}catch(e){L(e)}}function Rt(t,e){let n=u.config?.logger,o=typeof n?.warn=="function"?n.warn:n?.info;if(typeof o=="function")try{o.call(n,`@webority/analytics: ${t}: ${me(e)}`)}catch(r){L(r)}}function me(t){return typeof t=="object"&&t!==null&&"message"in t&&t.message!==void 0&&t.message!==null?t.message:t}function L(t){queueMicrotask(()=>{throw t})}var ye=new Set(["token","code","email","access_token","id_token","state","session_state","password","search","q","query"]),_e=/(?:access_token|id_token|session_state|token|code|state|email|password)=/i,Ce=["$current_url","$referrer","$pathname","$initial_current_url","$initial_referrer","$initial_pathname","$session_entry_url","$session_entry_referrer","$session_entry_pathname"],Ee=4,Se=5,be=6;function T(t){if(typeof t!="string")return t;let e=t.indexOf("#"),n=e===-1?t:t.slice(0,e),o=e===-1||_e.test(t.slice(e))?"":t.slice(e),r=n.indexOf("?");if(r===-1)return n+o;let i=n.slice(r+1).split("&"),c=i.filter(p=>!ye.has(Ie(p))).map(we);if(c.length===i.length&&c.every((p,w)=>p===i[w]))return n+o;let d=n.slice(0,r),y=c.filter(p=>p!=="").join("&");return(y?`${d}?${y}`:d)+o}function kt(t){if(!S(t))return t;let e=t.properties,n=S(e)?e:void 0;for(let i of[e,t.$set,t.$set_once,n?.$set,n?.$set_once])Te(i);let o=n?.$heatmap_data;if(n&&S(o)){let i={};for(let[c,d]of Object.entries(o)){let y=T(c),p=i[y];i[y]=Array.isArray(p)?p.concat(d):d}n.$heatmap_data=i}if(n){for(let[i,c]of Object.entries(n))if(i.startsWith("$web_vitals_")&&i.endsWith("_event")&&S(c))for(let d of["$current_url","navigationURL"]){let y=c[d];typeof y=="string"&&(c[d]=T(y))}}let r=n?.$snapshot_data;if(t.event==="$snapshot"&&r&&typeof r=="object"){let i=Array.isArray(r)?r:[r];for(let c of i)he(c)}return t}function he(t){if(!S(t))return;let e=t.data;if(S(e)){if(t.type===Ee)x(e,["href"]);else if(t.type===Se)x(e.payload,["href"]);else if(t.type===be){let n=e.payload;if(S(n)&&Array.isArray(n.requests))for(let o of n.requests)x(o,["name","url"])}}}function x(t,e){if(S(t))for(let n of e){let o=t[n];typeof o=="string"&&(t[n]=T(o))}}function Te(t){x(t,Ce)}function we(t){let e=t.indexOf("=");if(e===-1)return t;let n=t.slice(e+1).replace(/\+/g," "),o;try{o=decodeURIComponent(n)}catch{o=Nt(n)}if(!o.startsWith("/")&&!/^https?:\/\//i.test(o))return t;let r=T(o);return r===o?t:`${t.slice(0,e)}=${encodeURIComponent(r)}`}function Ie(t){let e=t.replace(/\+/g," "),n;try{n=decodeURIComponent(e)}catch{n=Nt(e)}return(n.split("=",1)[0]??"").toLowerCase()}function Nt(t){return t.replace(/%([0-9a-f]{2})/gi,(e,n)=>{let o=Number.parseInt(n,16);return o<128?String.fromCharCode(o):e})}function S(t){return typeof t=="object"&&t!==null}async function gn(){if(u.posthogInstance)return u.posthogInstance;if(u.posthogInitPromise)return u.posthogInitPromise;let t=u.config;if(!t)throw new Error("@webority/analytics: initAnalytics has not run.");return u.posthogInitPromise=import("posthog-js").then(e=>{let n=e.default??e,o=Q(X(t),D(),t.featureFlags===!0);return n.init(t.clientKey,o),n.register({product:t.product,surface:t.surface,environment:t.environment}),D()?n.opt_in_capturing({captureEventName:!1}):n.opt_out_capturing(),u.posthogInstance=n,Ot(n),n}).catch(e=>{throw u.posthogInitPromise=null,e}),u.posthogInitPromise}function Q(t,e,n=!1){return e?t:{...t,opt_out_capturing_by_default:!0,...n?{advanced_disable_feature_flags_on_first_load:!0}:{}}}function X(t){let e=t.sessionRecording??{},n={api_host:t.host,autocapture:!1,capture_pageview:"history_change",cookieless_mode:"on_reject",person_profiles:"identified_only",persistence:"localStorage+cookie",cross_subdomain_cookie:!0,disable_session_recording:!e.enabled,enable_heatmaps:t.heatmaps===!0,capture_exceptions:t.captureExceptions===!0,capture_performance:{web_vitals:!1},disable_surveys:!0,disable_product_tours:!0,disable_conversations:!0,advanced_disable_feature_flags:!(e.enabled||t.featureFlags===!0),before_send:kt};if(e.enabled){let o={maskAllInputs:e.maskAllInputs??!0,...e.maskTextSelector?{maskTextSelector:e.maskTextSelector}:{},maskCapturedNetworkRequestFn:r=>({...r,name:T(r.name)}),recordBody:!1,recordHeaders:!1};n.session_recording=o}return n}var Ae=()=>import("posthog-js"),Oe=100,l={config:null,posthog:null,pending:[],failed:!1,loadPosthog:Ae,startVitals:bt,stopFollowingConsent:null};function ve({host:t,clientKey:e,product:n,surface:o,environment:r,enabled:i=!0,sessionRecording:c,heatmaps:d=!1,captureExceptions:y=!1,webVitals:p=!1}={}){if(!C())throw new Error("@webority/analytics: call initConsent before initSiteAnalytics.");let w=et(p);if(!i||!t||!e||r==="Local"||l.config)return;let I={host:t,clientKey:e,product:n,surface:o,environment:r,sessionRecording:c,heatmaps:d,captureExceptions:y,webVitals:w};l.config=I,l.stopFollowingConsent=E(b=>ke(b.analytics)),N(()=>{Promise.resolve().then(l.loadPosthog).then(b=>Re(b.default??b,I)).catch(()=>{l.failed=!0,l.pending=[]})})}function Re(t,e){let n=f().analytics;t.init(e.clientKey,Q(Ne(e),n)),t.register({product:e.product,surface:e.surface,environment:e.environment}),n?t.opt_in_capturing({captureEventName:!1}):t.opt_out_capturing(),l.posthog=t;let o=l.pending;l.pending=[];for(let[r,i]of o)J(t,r,i);e.webVitals&&l.startVitals(e.webVitals,(r,i)=>J(t,r,i))}function ke(t){l.posthog&&(t?l.posthog.opt_in_capturing():l.posthog.opt_out_capturing())}function Ne(t){return{...X({host:t.host,sessionRecording:t.sessionRecording,heatmaps:t.heatmaps,captureExceptions:t.captureExceptions}),capture_pageview:!0}}function Dt(t,e){let n=l.config;if(!n)return;let o={...e,product:n.product,surface:n.surface,environment:n.environment};l.posthog?J(l.posthog,t,o):!l.failed&&l.pending.length<Oe&&l.pending.push([t,o])}function J(t,e,n){try{t.capture(e,n)}catch{}}function De(t,e={}){j.assertRegistered(t);let n=f().analytics,o=z(),r={...e};for(let[i,c]of[["first",o?.firstTouch],["last",o?.lastTouch]])c&&(r[`${i}_touch_channel`]=A(c),c.aiSource&&(r[`${i}_touch_ai_source`]=c.aiSource));return Dt(t,r),n?(window.dataLayer=window.dataLayer||[],window.dataLayer.push({...r,event:t}),!0):!1}function Pe(t){j.register(t)}var Le="https://www.googletagmanager.com/gtm.js",xe=3e3,Fe=100,_={loaded:!1,clarityId:null,clarityLoaded:!1,cancelClaritySchedule:null};function Ue(t={}){if(!C())throw new Error("@webority/analytics: call initConsent before loadTags.");if(_.loaded)return;_.loaded=!0;let{gtmId:e,gtmUrl:n=Le,clarityId:o,ahrefsKey:r}=t;if(typeof n!="string"||n.trim()==="")throw new Error("@webority/analytics: gtmUrl must be a non-empty string.");let i=lt();if(r){let c=()=>tt("https://analytics.ahrefs.com/analytics.js",{"data-key":r});i?Pt(d=>d.analytics,c):c()}if(e){let c=H(),d=b=>b.analytics||b.marketing&&c,y=()=>{window.dataLayer=window.dataLayer||[],window.dataLayer.push({"gtm.start":Date.now(),event:"gtm.js"}),tt(`${n}${n.includes("?")?"&":"?"}id=${encodeURIComponent(e)}`)},p=f(),w=p.decided&&d(p)?Me:N,I=()=>w(y);i?Pt(d,I):I()}o&&(_.clarityId=o,f().analytics&&He(),E(c=>{c.analytics&&!_.clarityLoaded?Z():_.clarityLoaded&&Lt(c)}))}function Pt(t,e){if(t(f())){e();return}let n=E(o=>{t(o)&&(n(),e())})}function Me(t){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function He(){let t=()=>{window.scrollY>Fe&&Z()};window.addEventListener("scroll",t,{passive:!0});let e=setTimeout(Z,xe);_.cancelClaritySchedule=()=>{window.removeEventListener("scroll",t),clearTimeout(e)}}function Z(){if(_.cancelClaritySchedule?.(),_.cancelClaritySchedule=null,_.clarityLoaded||!_.clarityId)return;_.clarityLoaded=!0;let t=function(){t.q=t.q||[],t.q.push(arguments)};window.clarity=window.clarity||t,Lt(f()),tt(`https://www.clarity.ms/tag/${encodeURIComponent(_.clarityId)}`,{crossorigin:"anonymous"})}function Lt(t){window.clarity?.("consentv2",{ad_Storage:t.marketing&&H()?"granted":"denied",analytics_Storage:t.analytics?"granted":"denied"})}function tt(t,e={}){let n=document.createElement("script");n.async=!0,n.src=t;for(let[o,r]of Object.entries(e))n.setAttribute(o,r);document.head.appendChild(n)}export{qt as a,v as b,ct as c,zt as d,Kt as e,C as f,f as g,jt as h,E as i,s as j,Ye as k,j as l,u as m,en as n,pe as o,D as p,rn as q,sn as r,an as s,gn as t,g as u,A as v,F as w,se as x,z as y,ve as z,De as A,Pe as B,Ue as C};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p={sampleRate:1,softNavigations:!0,deployVersion:null,pageTemplate:null};function T(e){if(e==null||e===!1)return null;if(e===!0)return{...p};if(typeof e!="object")throw new Error("@webority/analytics: webVitals takes true or { sampleRate, softNavigations, deployVersion, pageTemplate }.");let t=e,r=t.sampleRate??p.sampleRate;if(typeof r!="number"||!(r>0&&r<=1))throw new Error("@webority/analytics: webVitals.sampleRate must be a number above 0 and at most 1.");let o=t.deployVersion??null;if(o!==null&&typeof o!="string")throw new Error("@webority/analytics: webVitals.deployVersion must be a string.");let n=t.pageTemplate??null;if(n!==null&&(typeof n!="string"||n.length>120))throw new Error("@webority/analytics: webVitals.pageTemplate must be a string of at most 120 characters.");return{sampleRate:r,softNavigations:t.softNavigations!==!1,deployVersion:o,pageTemplate:n}}function y(e,t){return t<e}function b({mobileHint:e,screenWidth:t}){return e===!0?"mobile":typeof t!="number"||t<=0?"unknown":t<768?"mobile":t<1024?"tablet":"desktop"}function _(e,t){if(typeof e!="string"||!e)return null;try{return new URL(e,t).pathname}catch{return null}}function u(e){return typeof e=="string"&&e?e.split(/[?#]/,1)[0]??null:null}var a=e=>typeof e=="number"&&Number.isFinite(e)?Math.round(e):null,d=(e,t)=>typeof e=="string"&&e?e.slice(0,t):null;function c(e){return typeof e?.transferSize!="number"||typeof e?.decodedBodySize!="number"?null:e.transferSize===0&&e.decodedBodySize>0?!0:e.transferSize>0?!1:null}function v(e){return{url:d(u(e.sourceURL),200),function:d(e.sourceFunctionName,80),invoker_type:e.invokerType??null,duration_ms:a(e.duration),forced_style_layout_ms:a(e.forcedStyleAndLayoutDuration)}}function S(e){let t=(e?.longAnimationFrameEntries??[]).flatMap(r=>r.scripts??[]);return t.length===0&&(t=[e?.longestScript?.entry].filter(r=>!!r)),t.length===0?null:(t.sort((r,o)=>(o.duration??0)-(r.duration??0)),t.slice(0,3).map(v))}function h(e,t){let r=e.name,o=r==="CLS"?Math.round(e.value*1e4)/1e4:a(e.value),n={[`$web_vitals_${r}_value`]:o,vital:r,value:o,rating:e.rating,metric_id:e.id,navigation_type:e.navigationType??null,path:_(e.navigationURL??t.pageUrl,t.pageUrl),deploy_version:t.deployVersion??null,device_class:t.deviceClass,page_template:e.navigationType==="soft-navigation"?null:t.pageTemplate??null};if(e.name==="INP"){let i=e.attribution??{};n.inp_target=i.interactionTarget||null,n.inp_longest_script_url=u(i.longestScript?.entry?.sourceURL),n.inp_input_delay_ms=a(i.inputDelay),n.inp_processing_ms=a(i.processingDuration),n.inp_presentation_delay_ms=a(i.presentationDelay),n.inp_interaction_type=i.interactionType??null,n.inp_load_state=i.loadState??null,n.inp_scripts=S(i)}if(e.name==="LCP"){let i=e.attribution??{};n.lcp_ttfb_ms=a(i.timeToFirstByte),n.lcp_resource_load_delay_ms=a(i.resourceLoadDelay),n.lcp_resource_load_duration_ms=a(i.resourceLoadDuration),n.lcp_element_render_delay_ms=a(i.elementRenderDelay),n.lcp_target=i.target??null,n.lcp_url=/^(?:data|blob):/.test(i.url??"")?"data:":u(i.url),n.lcp_element_tag=i.lcpEntry?.element?.tagName?.toLowerCase()??null,n.lcp_nav_cached=c(i.navigationEntry),n.lcp_resource_cached=c(i.lcpResourceEntry)}if(e.name==="CLS"){let i=e.attribution??{};n.cls_target=i.largestShiftTarget??null,n.cls_largest_shift=typeof i.largestShiftValue=="number"&&Number.isFinite(i.largestShiftValue)?Math.round(i.largestShiftValue*1e4)/1e4:null,n.cls_largest_shift_time_ms=a(i.largestShiftTime),n.cls_load_state=i.loadState??null}return n}var s={started:!1,send:null};function P(e,t,{load:r=()=>import("./web-vitals.attribution-NGD57Y3S.js"),roll:o=Math.random()}={}){if(s.send=t,s.started||(s.started=!0,!y(e.sampleRate,o)))return Promise.resolve();let n=globalThis.navigator,i={deployVersion:e.deployVersion,pageTemplate:e.pageTemplate,deviceClass:b({mobileHint:n?.userAgentData?.mobile,screenWidth:globalThis.screen?.width})},f=l=>{try{s.send?.("$web_vitals",h(l,{...i,pageUrl:globalThis.location?.href}))}catch{}},g={reportSoftNavs:e.softNavigations};return Promise.resolve().then(r).then(l=>{for(let m of[l.onLCP,l.onINP,l.onCLS,l.onFCP,l.onTTFB])m(f,g)}).catch(()=>{})}function R(){s.started=!1,s.send=null}export{T as a,y as b,b as c,c as d,S as e,h as f,P as g,R as h};
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-O2XFH626.js";var e={started:!1,posthog:null,pending:[],loadPosthog:()=>import("posthog-js")};function
|
|
1
|
+
import"./chunk-O2XFH626.js";var e={started:!1,posthog:null,pending:[],loadPosthog:()=>import("posthog-js")};function f({host:t}){return{api_host:t,capture_exceptions:!0,capture_pageview:!1,capture_pageleave:!1,autocapture:!1,persistence:"memory",disable_session_recording:!0,disable_surveys:!0,advanced_disable_feature_flags:!0,person_profiles:"never",save_referrer:!1}}function P({host:t,clientKey:n,product:o,surface:d,environment:s,release:g,enabled:p=!0}={}){if(!(!p||s==="Local"||e.started)){if(!t||!n||!o||!s)throw new Error("@webority/analytics: initErrorTracking needs host, clientKey, product and environment.");e.started=!0,Promise.resolve().then(e.loadPosthog).then(i=>{let r=i.default??i;r.init(n,f({host:t})),r.register(h({product:o,surface:d,environment:s,release:g})),e.posthog=r;let u=e.pending;e.pending=[];for(let[c,l]of u)a(r,c,l)}).catch(()=>{e.pending=[]})}}function E(t,n){e.started&&(e.posthog?a(e.posthog,t,n):e.pending.length<20&&e.pending.push([t,n]))}function a(t,n,o){try{t.captureException(n,o)}catch{}}function h(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>n!==void 0))}function _(t=()=>import("posthog-js")){e.started=!1,e.posthog=null,e.pending=[],e.loadPosthog=t}export{f as buildErrorTrackingInitOptions,E as captureBrowserException,P as initErrorTracking,_ as resetErrorTrackingForTests};
|
package/dist/generate-events.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as
|
|
3
|
-
`)}function
|
|
4
|
-
`)}function
|
|
5
|
-
|
|
6
|
-
${
|
|
7
|
-
${
|
|
8
|
-
`);for(let e of
|
|
9
|
-
`);process.exit(1)}var
|
|
10
|
-
`):null;s
|
|
11
|
-
`));continue}
|
|
12
|
-
`)}
|
|
13
|
-
`);function
|
|
2
|
+
import{existsSync as pe,readFileSync as le,writeFileSync as ue}from"node:fs";import{basename as de,resolve as fe}from"node:path";import{parseArgs as ge}from"node:util";var o=Object.freeze({SIGNUP_STARTED:"signup_started",SIGNUP_COMPLETED:"signup_completed",LOGIN_SUCCEEDED:"login_succeeded",ONBOARDING_STARTED:"onboarding_started",ONBOARDING_STEP_COMPLETED:"onboarding_step_completed",ONBOARDING_COMPLETED:"onboarding_completed",SUBSCRIPTION_ACTIVATED:"subscription_activated",SUBSCRIPTION_CANCELLED:"subscription_cancelled",PAYMENT_SUCCEEDED:"payment_succeeded",PAYMENT_FAILED:"payment_failed",FEEDBACK_SUBMITTED:"feedback_submitted",LEAD_SUBMITTED:"lead_submitted",LEAD_QUALIFIED:"lead_qualified",LEAD_WON:"lead_won",WHATSAPP_CLICK:"whatsapp_click",CALCULATOR_USE:"calculator_use",PHONE_CLICK:"phone_click",DEMO_BOOKED:"demo_booked",CONTACT_SUBMITTED:"contact_submitted",TRIAL_START_CLICK:"trial_start_click",SAMPLE_REPORT_DOWNLOAD:"sample_report_download",REPORT_VERIFIED:"report_verified",CONTENT_ENGAGED:"content_engaged",EMAIL_CLICK:"email_click",PAGE_NOT_FOUND:"page_not_found",CHAT_OPENED:"chat_opened",CHAT_STARTED:"chat_started",CHAT_INPUT_SUBMITTED:"chat_input_submitted",CHAT_HANDOFF_REQUESTED:"chat_handoff_requested",CHAT_RATED:"chat_rated",CHAT_ACTION_REPEATED:"chat_action_repeated",TOUR_STARTED:"tour_started",TOUR_STEP_VIEWED:"tour_step_viewed",TOUR_COMPLETED:"tour_completed",TOUR_SKIPPED:"tour_skipped"}),_e=Object.freeze({signupStarted:o.SIGNUP_STARTED,signupCompleted:o.SIGNUP_COMPLETED,loginSucceeded:o.LOGIN_SUCCEEDED,onboardingStarted:o.ONBOARDING_STARTED,onboardingStepCompleted:o.ONBOARDING_STEP_COMPLETED,onboardingCompleted:o.ONBOARDING_COMPLETED,subscriptionActivated:o.SUBSCRIPTION_ACTIVATED,subscriptionCancelled:o.SUBSCRIPTION_CANCELLED,paymentSucceeded:o.PAYMENT_SUCCEEDED,paymentFailed:o.PAYMENT_FAILED,feedbackSubmitted:o.FEEDBACK_SUBMITTED,leadSubmitted:o.LEAD_SUBMITTED,leadQualified:o.LEAD_QUALIFIED,leadWon:o.LEAD_WON,whatsappClick:o.WHATSAPP_CLICK,calculatorUse:o.CALCULATOR_USE,phoneClick:o.PHONE_CLICK,demoBooked:o.DEMO_BOOKED,contactSubmitted:o.CONTACT_SUBMITTED,trialStartClick:o.TRIAL_START_CLICK,sampleReportDownload:o.SAMPLE_REPORT_DOWNLOAD,reportVerified:o.REPORT_VERIFIED,contentEngaged:o.CONTENT_ENGAGED,emailClick:o.EMAIL_CLICK,pageNotFound:o.PAGE_NOT_FOUND,chatOpened:o.CHAT_OPENED,chatStarted:o.CHAT_STARTED,chatInputSubmitted:o.CHAT_INPUT_SUBMITTED,chatHandoffRequested:o.CHAT_HANDOFF_REQUESTED,chatRated:o.CHAT_RATED,chatActionRepeated:o.CHAT_ACTION_REPEATED,tourStarted:o.TOUR_STARTED,tourStepViewed:o.TOUR_STEP_VIEWED,tourCompleted:o.TOUR_COMPLETED,tourSkipped:o.TOUR_SKIPPED}),O=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;function b(e){return e.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function N(e,{sender:s=null,productOnly:n=!1}={}){return[...e.events.values()].filter(t=>(!s||t.senders.includes(s))&&(!n||t.origin===e.product))}function k(e,{exportName:s="events",keys:n="constant",planLabel:t="tracking-plan.json"}={}){let r=[`// Generated by webority-analytics-generate-events from ${t}. Do not edit: change the plan and run the generator.`,`export const ${s} = Object.freeze({`];for(let i of e)r.push(` // ${x(i.description)} (${i.stage})`),r.push(` ${n==="pascal"?b(i.name):i.name.toUpperCase()}: "${i.name}",`);return r.push("});",""),r.join(`
|
|
3
|
+
`)}function R(e,{namespace:s,className:n,accessibility:t="public",planLabel:r="tracking-plan.json"}){let i=["// <auto-generated>",`// Generated by webority-analytics-generate-events from ${r}. Do not edit: change the plan and run the generator.`,"// </auto-generated>","",`namespace ${s};`,"","/// <summary>",`/// Event names from ${v(r)}.`,"/// </summary>",`${t} static class ${n}`,"{"];return e.forEach((p,f)=>{f>0&&i.push(""),i.push(` /// <summary>${v(x(p.description))} Stage: ${p.stage}.</summary>`),i.push(` public const string ${b(p.name)} = "${p.name}";`)}),i.push("}",""),i.join(`
|
|
4
|
+
`)}function x(e){return String(e??"").replace(/\s+/g," ").trim()}function v(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}import{readFileSync as q}from"node:fs";import{dirname as J,resolve as w}from"node:path";var M="@webority/analytics/fleet",L=Object.freeze(["acquisition","activation","engagement","retention","revenue","referral","support","quality"]),_=Object.freeze(["none","pseudonymous","personal"]),j=Object.freeze(["string","integer","number","boolean","array","object"]),U=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,Q=Object.freeze(["csharp","javascript"]),F=new Set(["properties","senders"]),X=new Set(["$schema","product","extends","description","commonProperties","events","sources"]),Z=new Set(["description","stage","owner","personalData","senders","properties"]),ee=new Set(["type","description","values","nullable","personalData"]),ne=new Set(["sender","language","constants","references","calls","ignoreConstants","scan","exclude"]),te=/^[A-Za-z_$][\w$]*$/,I=4,se=new URL("./fleet-tracking-plan.json",import.meta.url);function G(e){return B(w(e),0)}function B(e,s){let n=typeof e=="string"?e:"fleet-tracking-plan.json",t;try{t=JSON.parse(q(e,"utf8"))}catch(p){return{plan:null,problems:[`${n}: cannot read the plan (${ce(p)})`]}}if(!ae(t,n))return{plan:null,problems:K(t,n)};let r=null;if(t.extends!==void 0){if(s>=I)return{plan:null,problems:[`${n}: "extends" is nested more than ${I} deep`]};let p=t.extends===M?se:w(J(String(e)),t.extends),f=B(p,s+1);if(!f.plan)return{plan:null,problems:f.problems};r=f.plan}let i=re(r,t,n);return{plan:i.plan,problems:i.problems}}function re(e,s,n="plan"){let t=[],r=new Map,i=new Map(e?.commonProperties);if(e)for(let[c,a]of e.events)r.set(c,{...a,properties:new Map(a.properties),senders:[...a.senders]});for(let[c,a]of Object.entries(s.commonProperties??{})){let l=i.get(c);if(l&&l.type!==a.type){t.push(`${n}: common property "${c}" is ${a.type} here but ${l.type} in the base plan`);continue}i.set(c,{...a,origin:l?.origin??s.product})}for(let[c,a]of Object.entries(s.events??{})){let l=r.get(c);if(!l){let d=["description","stage","owner","personalData"].filter(E=>a[E]===void 0);d.length>0&&t.push(`${n}: event "${c}" is not in the base plan, so it needs description, stage, owner and personalData (missing ${d.join(", ")})`),r.set(c,{name:c,description:a.description,stage:a.stage,owner:a.owner,personalData:a.personalData,senders:[...a.senders??[]],properties:new Map(Object.entries(a.properties??{})),origin:s.product});continue}for(let d of Object.keys(a))F.has(d)||t.push(`${n}: event "${c}" is defined by the base plan, so it may only add properties or senders (found "${d}")`);for(let d of a.senders??[])l.senders.includes(d)||l.senders.push(d);for(let[d,E]of Object.entries(a.properties??{})){let T=l.properties.get(d);if(T&&T.type!==E.type){t.push(`${n}: "${c}.${d}" is ${E.type} here but ${T.type} in the base plan`);continue}l.properties.set(d,E)}}for(let[c,a]of r)for(let l of a.properties.keys())i.has(l)&&t.push(`${n}: "${c}.${l}" is already a common property, so it must not be declared on the event`);let p=s.sources??[],f=new Set(p.map(c=>c.sender));if(p.length>0)for(let[c,a]of Object.entries(s.events??{}))for(let l of a.senders??[])f.has(l)||t.push(`${n}: event "${c}" names sender "${l}", which no source declares`);return{plan:{product:s.product,events:r,commonProperties:i,sources:p,file:n},problems:t}}function K(e,s="plan"){let n=[],t=r=>{n.push(`${s}: ${r}`)};if(!g(e))return t("the plan must be a JSON object"),n;if(S(e,X,"the plan",t),(typeof e.product!="string"||!U.test(e.product))&&t('"product" must be a snake_case product slug'),e.extends!==void 0&&(typeof e.extends!="string"||e.extends.length===0)&&t(`"extends" must be "${M}" or a path to another plan`),!g(e.events))t('"events" must be an object keyed by event name');else for(let[r,i]of Object.entries(e.events))oe(r,i,t);if(e.commonProperties!==void 0&&H("commonProperties",e.commonProperties,t),e.sources!==void 0)if(!m(e.sources))t('"sources" must be an array');else for(let[r,i]of e.sources.entries())ie(i,r,t);return n}function oe(e,s,n){if(O.test(e)||n(`event "${e}" is not a snake_case name`),!g(s)){n(`event "${e}" must be an object`);return}S(s,Z,`event "${e}"`,n),Object.keys(s).every(r=>F.has(r))||((typeof s.description!="string"||s.description.trim()==="")&&n(`event "${e}" needs a description`),y(L,s.stage)||n(`event "${e}" stage must be one of ${L.join(", ")}`),(typeof s.owner!="string"||s.owner.trim()==="")&&n(`event "${e}" needs an owner`),y(_,s.personalData)||n(`event "${e}" personalData must be one of ${_.join(", ")}`)),s.senders!==void 0&&(!m(s.senders)||s.senders.some(r=>typeof r!="string"))&&n(`event "${e}" senders must be an array of sender names`),s.properties!==void 0&&H(`event "${e}"`,s.properties,n)}function H(e,s,n){if(!g(s)){n(`${e} properties must be an object keyed by property name`);return}for(let[t,r]of Object.entries(s)){if(U.test(t)||n(`${e} property "${t}" is not a snake_case name`),!g(r)){n(`${e} property "${t}" must be an object`);continue}S(r,ee,`${e} property "${t}"`,n),y(j,r.type)||n(`${e} property "${t}" type must be one of ${j.join(", ")}`),r.values!==void 0&&(!m(r.values)||r.values.length===0)&&n(`${e} property "${t}" values must be a non-empty array`),r.nullable!==void 0&&typeof r.nullable!="boolean"&&n(`${e} property "${t}" nullable must be true or false`),r.personalData!==void 0&&!y(_,r.personalData)&&n(`${e} property "${t}" personalData must be one of ${_.join(", ")}`)}}function ie(e,s,n){let t=`sources[${s}]`;if(!g(e)){n(`${t} must be an object`);return}S(e,ne,t,n),(typeof e.sender!="string"||e.sender==="")&&n(`${t} needs a sender`),y(Q,e.language)||n(`${t} language must be csharp or javascript`);for(let i of["constants","references","calls","ignoreConstants","scan","exclude"]){let p=e[i];p!==void 0&&(!m(p)||p.some(f=>typeof f!="string"))&&n(`${t} ${i} must be an array of strings`)}let r=e.calls;m(r)&&r.some(i=>typeof i=="string"&&!te.test(i))&&n(`${t} calls must be function names, such as trackSiteEvent`),$(e.constants)===0&&($(e.references)>0||$(e.calls)===0)&&n(`${t} needs at least one constants file, unless it has calls and no references`)}function $(e){return m(e)||typeof e=="string"?e.length:0}function S(e,s,n,t){for(let r of Object.keys(e))s.has(r)||t(`${n} has an unknown field "${r}"`)}function ae(e,s){return K(e,s).length===0}function g(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function m(e){return Array.isArray(e)}function y(e,s){return e.some(n=>n===s)}function ce(e){return e instanceof Error?e.message:String(e)}var A=`usage: webority-analytics-generate-events --plan <tracking-plan.json> [--js <file> [--js-export <name>] [--js-keys constant|pascal]] [--cs <file> --cs-namespace <ns> --cs-class <name> [--cs-internal]] [--sender <sender>] [--product-only] [--check]
|
|
5
|
+
`;function me(){try{return ge({options:{plan:{type:"string"},js:{type:"string"},"js-export":{type:"string"},"js-keys":{type:"string"},cs:{type:"string"},"cs-namespace":{type:"string"},"cs-class":{type:"string"},"cs-internal":{type:"boolean"},sender:{type:"string"},"product-only":{type:"boolean"},check:{type:"boolean"},help:{type:"boolean"}}}).values}catch(e){process.stderr.write(`${e instanceof Error?e.message:String(e)}
|
|
6
|
+
${A}`),process.exit(2)}}var u=me();u.help&&(process.stdout.write(A),process.exit(0));var z=ye(u);z&&(process.stderr.write(`${z}
|
|
7
|
+
${A}`),process.exit(2));var Y=u.plan??"",{plan:V,problems:P}=G(Y);if(!V||P.length>0){process.stderr.write(`The tracking plan has ${P.length} problem(s):
|
|
8
|
+
`);for(let e of P)process.stderr.write(` ${e}
|
|
9
|
+
`);process.exit(1)}var D=N(V,{sender:u.sender??null,productOnly:u["product-only"]??!1}),C=de(Y),h=[];u.js&&h.push([u.js,k(D,{exportName:u["js-export"]??"events",keys:Ee(u["js-keys"]),planLabel:C})]);u.cs&&h.push([u.cs,R(D,{namespace:u["cs-namespace"]??"",className:u["cs-class"]??"",accessibility:u["cs-internal"]?"internal":"public",planLabel:C})]);var W=0;for(let[e,s]of h){let n=fe(e);if(u.check){let t=pe(n)?le(n,"utf8").replace(/\r\n/g,`
|
|
10
|
+
`):null;t!==s&&(W++,process.stderr.write(`${e} is ${t===null?"missing":"out of date"}; run webority-analytics-generate-events without --check
|
|
11
|
+
`));continue}ue(n,s),process.stdout.write(`Wrote ${D.length} events to ${e}
|
|
12
|
+
`)}W>0&&process.exit(1);u.check&&process.stdout.write(`OK: ${h.length} generated file(s) match ${C}.
|
|
13
|
+
`);function Ee(e){return e==="pascal"?"pascal":"constant"}function ye(e){return e.plan?!e.js&&!e.cs?"pass --js, --cs or both":e.cs&&(!e["cs-namespace"]||!e["cs-class"])?"--cs needs --cs-namespace and --cs-class":e["js-keys"]&&!["constant","pascal"].includes(e["js-keys"])?"--js-keys is constant or pascal":null:"--plan is required"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as
|
|
1
|
+
import{A as X,B as Z,C as $,a as V,b as j,c as W,d as U,e as D,f as I,g as K,h as L,i as v,j as u,k as m,l as P,m as r,n as T,o as s,p as i,q as G,r as z,s as q,t as c,u as M,v as Y,w as B,x as J,y as Q}from"./chunk-NCVTY7BB.js";import{a as w,g as C}from"./chunk-S6QAWBSZ.js";import"./chunk-O2XFH626.js";var A=null,f=new Map,ee="workspace";function te(e){if(!I())throw new Error("@webority/analytics: call initConsent before initAnalytics.");let t=w(e.webVitals);A?.(),A=v(n=>re(n.analytics)),f.clear(),T({host:e.host,clientKey:e.clientKey,product:e.product,surface:e.surface,environment:e.environment,enabled:e.enabled??!0,logger:e.logger??null,sessionRecording:{enabled:e.sessionRecording?.enabled??!1,maskAllInputs:e.sessionRecording?.maskAllInputs??!0,maskTextSelector:e.sessionRecording?.maskTextSelector??null},heatmaps:e.heatmaps??!1,captureExceptions:e.captureExceptions??!1,webVitals:t,featureFlags:e.featureFlags===!0}),s()&&ne()}function ne(){let e=()=>{s()&&(R(),r.config?.webVitals&&C(r.config.webVitals,x))};typeof requestIdleCallback=="function"?requestIdleCallback(e,{timeout:3e3}):setTimeout(e,0)}function R(){c().catch(()=>{})}function re(e){if(s()){if(e){r.posthogInstance?(r.posthogInstance.opt_in_capturing(),O(r.posthogInstance),_(r.posthogInstance)):c().then(t=>{O(t),t&&_(t)}).catch(()=>{});return}!r.posthogInstance&&!r.posthogInitPromise&&R(),oe()}}function O(e){if(!e||!i())return;let t=r.pendingIdentify;t&&e.identify(t.publicId,t.props);for(let[n,{key:o,props:a}]of f)e.group(n,o,a)}function _(e){r.config?.featureFlags===!0&&i()&&e.reloadFeatureFlags?.()}function oe(){if(r.posthogInstance){r.posthogInstance.opt_out_capturing();return}r.posthogInitPromise&&r.posthogInitPromise.then(e=>{i()||e?.opt_out_capturing()}).catch(()=>{})}function ie(e,t={}){if(!s()){E("identify",{publicId:e,...t});return}r.pendingIdentify={publicId:e,props:t},i()&&c().then(n=>{!n||!i()||n.identify(e,t)}).catch(()=>{})}function se(e,t,n={}){if(typeof e!="string"||!e||typeof t!="string"||!t)throw new Error("@webority/analytics: group needs a type and a PublicId string.");if(!s()){E("group",{type:e,key:t,...n});return}f.set(e,{key:t,props:n}),i()&&c().then(o=>{!o||!i()||o.group(e,t,n)}).catch(()=>{})}function ae(){r.pendingIdentify=null,f.clear(),r.posthogInstance&&r.posthogInstance.reset()}function l(e,t={}){P.assertRegistered(e),x(e,t)}function x(e,t){let n=r.config;if(!n||!s()){E(e,t);return}let o={...t,product:n.product,surface:n.surface,environment:n.environment};c().then(a=>{a?.capture(e,o)}).catch(()=>{})}function E(e,t){r.config?.environment==="Local"&&r.config.logger?.info(e,t)}function ue(){if(typeof document>"u")return()=>{};for(let[e,t]of Object.entries(S))document.addEventListener(e,t);return()=>{for(let[e,t]of Object.entries(S))document.removeEventListener(e,t)}}function ce(e){d(u.TOUR_STARTED,e,{step_count:p(b(e)?.total)})}function le(e){let t=b(e);d(u.TOUR_STEP_VIEWED,e,{step_position:p(t?.position),step_count:p(t?.total)})}function pe(e){let t=b(e),n={step_position:p(t?.position),step_count:p(t?.total)};t?.reason==="finished"?d(u.TOUR_COMPLETED,e,n):t?.reason==="skipped"&&d(u.TOUR_SKIPPED,e,{...n,via:y(t.via)})}var S={"wui-tour:start":ce,"wui-tour:step":le,"wui-tour:close":pe};function d(e,t,n){let o=t.target,a=y(N(o,"tour-id"));if(!a)return;let g={tour_id:a},h=y(N(o,"trigger"));h&&(g.trigger=h);for(let[F,k]of Object.entries(n))k!==void 0&&(g[F]=k);l(e,g)}function fe(e){return typeof e=="object"&&e!==null&&"getAttribute"in e&&typeof e.getAttribute=="function"}function N(e,t){return fe(e)?e.getAttribute(t):void 0}function b(e){let t="detail"in e?e.detail:void 0;return typeof t=="object"&&t!==null?t:void 0}function p(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:void 0}function y(e){return typeof e=="string"&&e!==""?e:void 0}function de(e){return Object.keys(m).every(t=>typeof e[t]=="function")}var H=Object.fromEntries(Object.entries(m).map(([e,t])=>[e,(n={})=>l(t,n)]));if(!de(H))throw new Error("@webority/analytics: a track helper is missing its function.");var ge=Object.freeze(H);export{W as CONSENT_CHANGE_EVENT,j as CONSENT_COOKIE_NAME,ee as WORKSPACE_GROUP_TYPE,J as captureAttribution,M as channels,u as events,Q as getAttribution,K as getConsent,z as getFeatureFlag,se as group,ie as identify,te as initAnalytics,U as initConsent,G as isFeatureEnabled,$ as loadTags,v as onConsentChange,q as onFeatureFlags,Z as registerEvents,V as requiresOptIn,ae as resetIdentity,B as resolveAiSource,Y as resolveChannel,L as saveConsent,D as setConsentRegion,ge as track,l as trackEvent,X as trackSiteEvent,ue as trackTours};
|
package/dist/node.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PostHog as
|
|
1
|
+
import{PostHog as u}from"posthog-node";var r={client:null,base:{},createClient:(e,t)=>new u(e,t)};function f({host:e,clientKey:t,product:o,surface:i,environment:n,release:s,enabled:l=!0,captureUncaught:d=!0}={}){if(!(!l||n==="Local"||r.client!==null)){if(!e||!t||!o||!n)throw new Error("@webority/analytics: initServerErrorTracking needs host, clientKey, product and environment.");r.client=r.createClient(t,{host:e,flushAt:1,flushInterval:0,enableExceptionAutocapture:d}),r.base=a({product:o,surface:i,environment:n,release:s})}}function c(e,{distinctId:t,path:o,method:i,statusCode:n,properties:s}={}){if(r.client)try{r.client.captureException(e,t??"server",a({...r.base,...s,path:o,$current_url:o,method:i,statusCode:n}))}catch{}}function p(){return(e,t,o,i)=>{let n=typeof e=="object"&&e!==null||typeof e=="function"?e:void 0;c(e,{path:t.originalUrl,method:t.method,statusCode:(n&&"status"in n?n.status:void 0)??(n&&"statusCode"in n?n.statusCode:void 0)??500}),i(e)}}async function g(e=2e3){if(!r.client)return;let t;await Promise.race([r.client.flush(),new Promise(o=>{t=setTimeout(()=>o(),e)})]),clearTimeout(t),r.client=null}function E(e=(t,o)=>new u(t,o)){r.client=null,r.base={},r.createClient=e}function a(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}export{c as captureServerException,p as expressErrorHandler,g as flushServerErrorTracking,f as initServerErrorTracking,E as resetServerErrorTrackingForTests};
|
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var r=Object.freeze({SIGNUP_STARTED:"signup_started",SIGNUP_COMPLETED:"signup_completed",LOGIN_SUCCEEDED:"login_succeeded",ONBOARDING_STARTED:"onboarding_started",ONBOARDING_STEP_COMPLETED:"onboarding_step_completed",ONBOARDING_COMPLETED:"onboarding_completed",SUBSCRIPTION_ACTIVATED:"subscription_activated",SUBSCRIPTION_CANCELLED:"subscription_cancelled",PAYMENT_SUCCEEDED:"payment_succeeded",PAYMENT_FAILED:"payment_failed",FEEDBACK_SUBMITTED:"feedback_submitted",LEAD_SUBMITTED:"lead_submitted",LEAD_QUALIFIED:"lead_qualified",LEAD_WON:"lead_won",WHATSAPP_CLICK:"whatsapp_click",CALCULATOR_USE:"calculator_use",PHONE_CLICK:"phone_click",DEMO_BOOKED:"demo_booked",CONTACT_SUBMITTED:"contact_submitted",TRIAL_START_CLICK:"trial_start_click",SAMPLE_REPORT_DOWNLOAD:"sample_report_download",REPORT_VERIFIED:"report_verified",CONTENT_ENGAGED:"content_engaged",EMAIL_CLICK:"email_click",PAGE_NOT_FOUND:"page_not_found",CHAT_OPENED:"chat_opened",CHAT_STARTED:"chat_started",CHAT_INPUT_SUBMITTED:"chat_input_submitted",CHAT_HANDOFF_REQUESTED:"chat_handoff_requested",CHAT_RATED:"chat_rated",CHAT_ACTION_REPEATED:"chat_action_repeated",TOUR_STARTED:"tour_started",TOUR_STEP_VIEWED:"tour_step_viewed",TOUR_COMPLETED:"tour_completed",TOUR_SKIPPED:"tour_skipped"}),
|
|
1
|
+
var r=Object.freeze({SIGNUP_STARTED:"signup_started",SIGNUP_COMPLETED:"signup_completed",LOGIN_SUCCEEDED:"login_succeeded",ONBOARDING_STARTED:"onboarding_started",ONBOARDING_STEP_COMPLETED:"onboarding_step_completed",ONBOARDING_COMPLETED:"onboarding_completed",SUBSCRIPTION_ACTIVATED:"subscription_activated",SUBSCRIPTION_CANCELLED:"subscription_cancelled",PAYMENT_SUCCEEDED:"payment_succeeded",PAYMENT_FAILED:"payment_failed",FEEDBACK_SUBMITTED:"feedback_submitted",LEAD_SUBMITTED:"lead_submitted",LEAD_QUALIFIED:"lead_qualified",LEAD_WON:"lead_won",WHATSAPP_CLICK:"whatsapp_click",CALCULATOR_USE:"calculator_use",PHONE_CLICK:"phone_click",DEMO_BOOKED:"demo_booked",CONTACT_SUBMITTED:"contact_submitted",TRIAL_START_CLICK:"trial_start_click",SAMPLE_REPORT_DOWNLOAD:"sample_report_download",REPORT_VERIFIED:"report_verified",CONTENT_ENGAGED:"content_engaged",EMAIL_CLICK:"email_click",PAGE_NOT_FOUND:"page_not_found",CHAT_OPENED:"chat_opened",CHAT_STARTED:"chat_started",CHAT_INPUT_SUBMITTED:"chat_input_submitted",CHAT_HANDOFF_REQUESTED:"chat_handoff_requested",CHAT_RATED:"chat_rated",CHAT_ACTION_REPEATED:"chat_action_repeated",TOUR_STARTED:"tour_started",TOUR_STEP_VIEWED:"tour_step_viewed",TOUR_COMPLETED:"tour_completed",TOUR_SKIPPED:"tour_skipped"}),Q=Object.freeze({signupStarted:r.SIGNUP_STARTED,signupCompleted:r.SIGNUP_COMPLETED,loginSucceeded:r.LOGIN_SUCCEEDED,onboardingStarted:r.ONBOARDING_STARTED,onboardingStepCompleted:r.ONBOARDING_STEP_COMPLETED,onboardingCompleted:r.ONBOARDING_COMPLETED,subscriptionActivated:r.SUBSCRIPTION_ACTIVATED,subscriptionCancelled:r.SUBSCRIPTION_CANCELLED,paymentSucceeded:r.PAYMENT_SUCCEEDED,paymentFailed:r.PAYMENT_FAILED,feedbackSubmitted:r.FEEDBACK_SUBMITTED,leadSubmitted:r.LEAD_SUBMITTED,leadQualified:r.LEAD_QUALIFIED,leadWon:r.LEAD_WON,whatsappClick:r.WHATSAPP_CLICK,calculatorUse:r.CALCULATOR_USE,phoneClick:r.PHONE_CLICK,demoBooked:r.DEMO_BOOKED,contactSubmitted:r.CONTACT_SUBMITTED,trialStartClick:r.TRIAL_START_CLICK,sampleReportDownload:r.SAMPLE_REPORT_DOWNLOAD,reportVerified:r.REPORT_VERIFIED,contentEngaged:r.CONTENT_ENGAGED,emailClick:r.EMAIL_CLICK,pageNotFound:r.PAGE_NOT_FOUND,chatOpened:r.CHAT_OPENED,chatStarted:r.CHAT_STARTED,chatInputSubmitted:r.CHAT_INPUT_SUBMITTED,chatHandoffRequested:r.CHAT_HANDOFF_REQUESTED,chatRated:r.CHAT_RATED,chatActionRepeated:r.CHAT_ACTION_REPEATED,tourStarted:r.TOUR_STARTED,tourStepViewed:r.TOUR_STEP_VIEWED,tourCompleted:r.TOUR_COMPLETED,tourSkipped:r.TOUR_SKIPPED}),h=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;function S(){let e=new Set(Object.values(r));return{register(t){for(let o of t){if(!h.test(o))throw new Error(`@webority/analytics: invalid event name "${o}". Expected snake_case.`);e.add(o)}},assertRegistered(t){if(!e.has(t))throw new Error(`@webority/analytics: event "${t}" is not registered. Call registerEvents() first.`)}}}var b=null;function H(e){b=e}async function D(){if(b)return R(g(b,"PostHog"));try{let e=await import("posthog-react-native");return R(g(e,"PostHog")??g(g(e,"default"),"PostHog")??g(e,"default"))}catch(e){if(K(e))return null;throw e}}var x=/Unable to resolve module [`'"]?posthog-react-native[`'"]?(\s|$)|Cannot find (module|package) [`'"]posthog-react-native[`'"]/;function K(e){let t=g(e,"message");return x.test(typeof t=="string"?t:"")}function N(e){return{host:e.host,defaultOptIn:!1,personProfiles:"identified_only",captureAppLifecycleEvents:!1,enableSessionReplay:!1,preloadFeatureFlags:!1,disableRemoteFeatureFlags:e.featureFlags!==!0,disableSurveys:!0}}function G(e){return typeof e=="function"}function R(e){if(e==null)return null;if(!G(e))throw new TypeError("@webority/analytics: posthog-react-native loaded, but its PostHog export is not a class. Reinstall posthog-react-native.");return e}function B(e,t){return t in e}function g(e,t){if(!((typeof e!="object"||e===null)&&typeof e!="function"))return B(e,t)?e[t]:void 0}var P="webority_analytics_consent",V=["eea","other"],re="workspace",n={config:null,initPromise:null,posthog:null,requiresOptIn:!0,region:null,saved:null,pendingIdentify:null,pendingGroups:new Map,flagsLoaded:!1,failureReported:!1,consentUnreadable:!1},k=S(),C=new Set,p=new Set;function ie(e){if(n.initPromise)return n.initPromise;let t=f();return n.config={host:e?.host,clientKey:e?.clientKey,product:e?.product,surface:e?.surface,environment:e?.environment,enabled:e?.enabled??!0,logger:e?.logger??null,storage:e?.storage??null,featureFlags:e?.featureFlags===!0},n.requiresOptIn=e?.requiresOptIn!==!1,n.initPromise=q(t).catch(E),n.initPromise}async function q(e){let t=M(),o=n.saved,i=await j(t);o&&t?await a(()=>t.setItem(P,JSON.stringify(o))):!n.saved&&i&&(n.saved=i);let s=f();(e.analytics!==s.analytics||e.decided!==s.decided)&&w(s);let l=n.config;if(!_(l))return;let d;try{d=await D()}catch(U){c(U);return}if(!d){E(new Error("@webority/analytics: posthog-react-native is not installed, so nothing is sent."));return}let T=new d(l.clientKey,N(l));await T.ready?.(),await T.register(O(l)),n.posthog=T,W(T,l),await v(u())}function se(e){if(!V.includes(e))throw new Error('@webority/analytics: setConsentRegion needs "eea" or "other".');let t=f();n.region=e;let o=f();t.analytics!==o.analytics&&(v(o.analytics),w(o))}async function ae(e){let t={analytics:e===!0,savedAtUtc:new Date().toISOString()};n.saved=t,v(t.analytics),w(f());let o=M();o&&await a(()=>o.setItem(P,JSON.stringify(t)))}function f(){return n.saved?{analytics:n.saved.analytics,decided:!0}:n.consentUnreadable?{analytics:!1,decided:!1}:{analytics:!n.requiresOptIn||n.region==="other",decided:!1}}function le(e){return C.add(e),()=>C.delete(e)}function ue(e,t={}){if(n.config&&!_(n.config)){I("identify",{publicId:e,...t});return}n.pendingIdentify={publicId:e,props:t};let o=n.posthog;o&&u()&&a(()=>o.identify(e,t))}function ce(e,t,o={}){if(typeof e!="string"||!e||typeof t!="string"||!t)throw new Error("@webority/analytics: group needs a type and a PublicId string.");if(n.config&&!_(n.config)){I("group",{type:e,key:t,...o});return}n.pendingGroups.set(e,{key:t,props:o});let i=n.posthog;i&&u()&&a(()=>i.group(e,t,o))}function de(e){let t=A();if(!t)return!1;try{return t.isFeatureEnabled(e)===!0}catch(o){return m(`feature flag "${e}" could not be read, so it reads as off`,o),c(o),!1}}function ge(e){let t=A();if(!t)return null;try{return t.getFeatureFlag(e)??null}catch(o){return m(`feature flag "${e}" could not be read, so it reads as null`,o),c(o),null}}function fe(e){return p.add(e),(!A()||n.flagsLoaded)&&queueMicrotask(()=>{p.has(e)&&L(e)}),()=>p.delete(e)}function pe(){n.pendingIdentify=null,n.pendingGroups.clear();let e=n.posthog,t=n.config;!e||!t||a(async()=>{e.reset(),await e.register(O(t)),u()?await e.optIn():await e.optOut()})}function Ee(e){k.register(e)}function ye(e,t={}){k.assertRegistered(e),F(e,t,(o,i)=>o.capture(e,i))}function _e(e,t={}){F(e,t,(o,i)=>o.screen(e,i))}function F(e,t,o){let i=n.config;if(!_(i)){I(e,t);return}if(!u())return;let s={...t,...O(i)},l=n.posthog;if(l){a(()=>o(l,s));return}n.initPromise?.then(()=>{let d=n.posthog;d&&u()&&a(()=>o(d,s))})}function v(e){let t=n.posthog;return t?a(async()=>{if(!e){await t.optOut();return}await t.optIn(),$(t),n.config?.featureFlags&&await t.reloadFeatureFlagsAsync?.()}):Promise.resolve()}function W(e,t){!t.featureFlags||typeof e.onFeatureFlags!="function"||a(()=>e.onFeatureFlags?.(()=>{n.flagsLoaded=!0;for(let o of[...p])L(o)}))}function A(){return!n.config?.featureFlags||!_(n.config)||!u()?null:n.posthog}function L(e){try{e()}catch(t){c(t)}}function $(e){if(!u())return;let t=n.pendingIdentify;t&&e.identify(t.publicId,t.props);for(let[o,{key:i,props:s}]of n.pendingGroups)e.group(o,i,s)}function M(){let e=n.config?.storage??null;return n.config&&!e&&E(new Error("@webority/analytics: no storage was passed to initMobileAnalytics, so the choice lasts until the app closes.")),e}async function j(e){if(!e)return null;try{let t=await e.getItem(P);if(!t)return null;let o=JSON.parse(t),i=y(o,"analytics");if(typeof i!="boolean")return null;let s=y(o,"savedAtUtc");return{analytics:i,savedAtUtc:typeof s=="string"?s:null}}catch(t){return n.consentUnreadable=!0,Y(t),null}}function Y(e){m("the stored consent choice could not be read, so analytics stays off",e)||c(e)}function m(e,t){let o=n.config?.logger,i=typeof o?.warn=="function"?o.warn:o?.info;if(typeof i!="function")return!1;try{i.call(o,`@webority/analytics: ${e}: ${y(t,"message")??t}`)}catch(s){c(s)}return!0}function w(e){for(let t of C)try{t(e)}catch(o){c(o)}}function _(e){return!!(e?.enabled&&e.clientKey&&e.host&&e.environment!=="Local")}function u(){return f().analytics}function O(e){return{product:e.product,surface:e.surface,environment:e.environment}}function a(e){try{return Promise.resolve(e()).then(void 0,E)}catch(t){return E(t),Promise.resolve()}}function E(e){if(n.failureReported||(n.failureReported=!0,y(globalThis,"__DEV__")!==!0))return;let t=n.config?.logger,o=typeof t?.warn=="function"?t.warn:t?.info;if(typeof o=="function")try{o.call(t,`@webority/analytics: ${y(e,"message")??e}`)}catch(i){c(i)}}function c(e){queueMicrotask(()=>{throw e})}function I(e,t){n.config?.environment==="Local"&&n.config.logger?.info(e,t)}function z(e,t){return t in e}function y(e,t){if(!((typeof e!="object"||e===null)&&typeof e!="function"))return z(e,t)?e[t]:void 0}function Te(){n.config=null,n.initPromise=null,n.posthog=null,n.requiresOptIn=!0,n.region=null,n.saved=null,n.pendingIdentify=null,n.pendingGroups.clear(),n.flagsLoaded=!1,n.failureReported=!1,n.consentUnreadable=!1,C.clear(),p.clear()}export{P as CONSENT_STORAGE_KEY,re as WORKSPACE_GROUP_TYPE,Te as __resetForTests,H as __setNativeModulesForTests,r as events,f as getAnalyticsConsent,ge as getFeatureFlag,ce as group,ue as identify,ie as initMobileAnalytics,de as isFeatureEnabled,le as onAnalyticsConsentChange,fe as onFeatureFlags,Ee as registerEvents,pe as resetIdentity,ae as setAnalyticsConsent,se as setConsentRegion,ye as trackEvent,_e as trackScreen};
|
package/dist/site.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as p,B as q,C as r,a,b,c,d,e,g as f,h as g,i as h,j as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-
|
|
1
|
+
import{A as p,B as q,C as r,a,b,c,d,e,g as f,h as g,i as h,j as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-NCVTY7BB.js";import"./chunk-S6QAWBSZ.js";import"./chunk-O2XFH626.js";export{c as CONSENT_CHANGE_EVENT,b as CONSENT_COOKIE_NAME,m as captureAttribution,j as channels,i as events,n as getAttribution,f as getConsent,d as initConsent,o as initSiteAnalytics,r as loadTags,h as onConsentChange,q as registerEvents,a as requiresOptIn,l as resolveAiSource,k as resolveChannel,g as saveConsent,e as setConsentRegion,p as trackSiteEvent};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the callback once, on the visitor's first interaction or 1.5s after the page's load event,
|
|
3
|
+
* whichever comes first, so a third-party download never competes with the largest paint. Each
|
|
4
|
+
* call waits on its own: a call made after an earlier wait has fired waits again.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runAfterFirstInteraction(callback: () => void): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { EventName, EventProperties } from "./event-registry.ts";
|
|
2
|
+
import { type WebVitalsInput } from "./web-vitals.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The logger a product injects. info is required: events tracked while the environment is Local
|
|
5
|
+
* go to it, so a logger with only warn would fail there. warn, when given, takes a failed flag read;
|
|
6
|
+
* without it that failure goes to info.
|
|
7
|
+
*/
|
|
8
|
+
export type AnalyticsLogger = {
|
|
9
|
+
info: (name: string, props?: EventProperties) => void;
|
|
10
|
+
warn?: (message: string) => void;
|
|
11
|
+
};
|
|
12
|
+
type AnalyticsConfig = {
|
|
13
|
+
host: string;
|
|
14
|
+
clientKey: string;
|
|
15
|
+
product: string;
|
|
16
|
+
surface: string;
|
|
17
|
+
environment: string;
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
logger?: AnalyticsLogger;
|
|
20
|
+
sessionRecording?: {
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
maskAllInputs?: boolean;
|
|
23
|
+
maskTextSelector?: string;
|
|
24
|
+
};
|
|
25
|
+
heatmaps?: boolean;
|
|
26
|
+
captureExceptions?: boolean;
|
|
27
|
+
webVitals?: WebVitalsInput;
|
|
28
|
+
featureFlags?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare const WORKSPACE_GROUP_TYPE = "workspace";
|
|
31
|
+
/**
|
|
32
|
+
* Starts PostHog capture. initConsent must run first: the visitor's analytics consent decides
|
|
33
|
+
* how PostHog runs, so a surface with no consent source would capture under a choice nobody was
|
|
34
|
+
* offered. Without consent events are still sent, cookieless and anonymous; with it PostHog
|
|
35
|
+
* persists the visitor and identify applies.
|
|
36
|
+
*/
|
|
37
|
+
export declare function initAnalytics(config: AnalyticsConfig): void;
|
|
38
|
+
export declare function identify(publicId: string, props?: EventProperties): void;
|
|
39
|
+
/**
|
|
40
|
+
* PostHog group analytics (a paid add-on): ties this person's later events to a group, and sets
|
|
41
|
+
* the group's properties (plan, seats). For the workspace pass WORKSPACE_GROUP_TYPE and the
|
|
42
|
+
* workspace's PublicId; a number throws, because an internal id never reaches analytics.
|
|
43
|
+
* Same gate as identify: made before consent it is held and applied on the grant, the last one
|
|
44
|
+
* per type wins, and resetIdentity forgets it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function group(type: string, key: string, props?: EventProperties): void;
|
|
47
|
+
export declare function resetIdentity(): void;
|
|
48
|
+
export declare function trackEvent(name: EventName, props?: EventProperties): void;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const ATTRIBUTION_STORAGE_KEY = "webority_attribution";
|
|
2
|
+
export type AttributionTouch = {
|
|
3
|
+
utmSource?: string;
|
|
4
|
+
utmMedium?: string;
|
|
5
|
+
utmCampaign?: string;
|
|
6
|
+
utmContent?: string;
|
|
7
|
+
utmTerm?: string;
|
|
8
|
+
gclid?: string;
|
|
9
|
+
gbraid?: string;
|
|
10
|
+
wbraid?: string;
|
|
11
|
+
fbclid?: string;
|
|
12
|
+
msclkid?: string;
|
|
13
|
+
liFatId?: string;
|
|
14
|
+
referrer?: string;
|
|
15
|
+
aiSource?: string;
|
|
16
|
+
landingPage?: string;
|
|
17
|
+
capturedDateTimeUtc: string;
|
|
18
|
+
};
|
|
19
|
+
type AttributionRecord = {
|
|
20
|
+
firstTouch: AttributionTouch;
|
|
21
|
+
lastTouch: AttributionTouch;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Records how the visitor arrived: campaign parameters, click ids and an outside referrer.
|
|
25
|
+
* Call on every page load, before a client-side router strips the query string. The first
|
|
26
|
+
* touch is kept for 90 days; the last touch is replaced by each later campaign or referral
|
|
27
|
+
* visit. A direct visit changes nothing. Stored in localStorage only with marketing consent,
|
|
28
|
+
* otherwise for this tab alone.
|
|
29
|
+
*/
|
|
30
|
+
export declare function captureAttribution(): void;
|
|
31
|
+
/** { firstTouch, lastTouch }, or null when no campaign or referral visit is on record. */
|
|
32
|
+
export declare function getAttribution(): AttributionRecord | null;
|
|
33
|
+
export declare function resetAttributionForTests(): void;
|
|
34
|
+
export {};
|