@rebilly/lead-source-tracker 8.34.5 → 8.34.6

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.
Files changed (2) hide show
  1. package/dist/build.js +1 -1
  2. package/package.json +3 -3
package/dist/build.js CHANGED
@@ -1 +1 @@
1
- (function(l,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(l=typeof globalThis<"u"?globalThis:l||self,l.RebillyLeadSource=m())})(this,(function(){"use strict";/*! js-cookie v3.0.8 | MIT */function l(e){for(var o=1;o<arguments.length;o++){var r=arguments[o];for(var c in r)c!=="__proto__"&&(e[c]=r[c])}return e}var m={read:function(e){return e[0]==='"'&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function h(e,o){function r(n,u,i){if(!(typeof document>"u")){i=l({},o,i),typeof i.expires=="number"&&(i.expires=new Date(Date.now()+i.expires*864e5)),i.expires&&(i.expires=i.expires.toUTCString()),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var s in i)i[s]&&(a+="; "+s,i[s]!==!0&&(a+="="+i[s].split(";")[0]));return document.cookie=n+"="+e.write(u,n)+a}}function c(n){if(!(typeof document>"u"||arguments.length&&!n)){for(var u=document.cookie?document.cookie.split("; "):[],i={},a=0;a<u.length;a++){var s=u[a].split("="),f=s.slice(1).join("=");try{var d=decodeURIComponent(s[0]);if(d in i||(i[d]=e.read(f,d)),n===d)break}catch{}}return n?i[n]:i}}return Object.create({set:r,get:c,remove:function(n,u){r(n,"",l({},u,{expires:-1}))},withAttributes:function(n){return h(this.converter,l({},this.attributes,n))},withConverter:function(n){return h(l({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(e)}})}var g=h(m,{path:"/"});function t(e,o,r){return{test:c=>c===e||c.endsWith(`.${e}`),source:o,medium:r}}const b=[t("chatgpt.com","chatgpt","ai-assistant"),t("chat.openai.com","chatgpt","ai-assistant"),t("perplexity.ai","perplexity","ai-assistant"),t("claude.ai","claude","ai-assistant"),t("gemini.google.com","gemini","ai-assistant"),t("copilot.microsoft.com","copilot","ai-assistant"),t("mail.google.com","gmail","email"),t("outlook.live.com","outlook","email"),t("outlook.office.com","outlook","email"),t("mail.yahoo.com","yahoo-mail","email"),{test:e=>/^(www\.)?google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(e),source:"google",medium:"organic-search"},t("bing.com","bing","organic-search"),t("duckduckgo.com","duckduckgo","organic-search"),t("github.com","github","community"),t("stackoverflow.com","stack-overflow","community"),t("reddit.com","reddit","community"),t("news.ycombinator.com","hacker-news","community"),t("dev.to","dev-to","community"),t("linkedin.com","linkedin","social"),t("lnkd.in","linkedin","social"),t("twitter.com","x-twitter","social"),t("x.com","x-twitter","social"),t("t.co","x-twitter","social"),t("youtube.com","youtube","social"),t("youtu.be","youtube","social"),t("bsky.app","bluesky","social"),t("facebook.com","facebook","social"),t("fb.com","facebook","social"),t("fb.me","facebook","social"),t("instagram.com","instagram","social"),t("tiktok.com","tiktok","social"),t("snapchat.com","snapchat","social"),t("pinterest.com","pinterest","social"),t("pin.it","pinterest","social"),t("threads.net","threads","social"),t("threads.com","threads","social")];function D(e){if(!e)return null;let o;try{o=new URL(e).hostname.toLowerCase()}catch{return null}const r=b.find(c=>c.test(o));return r?{source:r.source,medium:r.medium}:null}function I(e){return[...e].map(o=>o.toString(16).padStart(2,"0")).join("")}function U(){if(typeof crypto>"u"||typeof crypto.getRandomValues!="function")return null;const e=new Uint8Array(16);crypto.getRandomValues(e);const o=Date.now();e[0]=Math.floor(o/1099511627776)&255,e[1]=Math.floor(o/4294967296)&255,e[2]=Math.floor(o/16777216)&255,e[3]=Math.floor(o/65536)&255,e[4]=Math.floor(o/256)&255,e[5]=o&255,e[6]=e[6]&15|112,e[8]=e[8]&63|128;const r=I(e);return`${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`}const k="rls",y={expires:45},O=["source","medium","campaign","term","content","affiliate","subAffiliate","clickId","salesAgent"],C=["path","referrer"],S=[...C,...O];function x(e,o){const{classifyReferrer:r=!1,visitorId:c=!1,...n}=o||{},{document:u}=e;if($(e))return p({dnt:!0}),{};const i={path:u.location.host+u.location.pathname,...A(u),..._(u),...F(e)};c&&delete i.clickId;const{leadSource:a}=T({leadSource:i},n,r,c);return a||{}}function p({dnt:e=!1}){const o={dnt:e};return e?R(o):g.remove(k,y),o}function L(){var e;return(e=v().leadSource)==null?void 0:e.clickId}function T(e,o,r=!1,c=!1){const n=v();if(n.dnt||e.dnt)return p({dnt:!0});p({dnt:!1});const u=n.leadSource||{},i=C.reduce((s,f)=>{const d=u[f];return d&&(s[f]=d),s},{}),a={leadSource:{...u,...w(e.leadSource),...i}};if(r){const s=a.leadSource;if(!s.source||!s.medium){const f=D(s.referrer);f&&(s.source=s.source||f.source,s.medium=s.medium||f.medium)}}if(c&&!a.leadSource.clickId){const s=U();s&&(a.leadSource.clickId=s)}return Object.assign(y,o||{}),R(a),a}function v(){const e=g.get(k);if(!e)return{};try{const o=JSON.parse(e);return o.dnt?{dnt:!0}:o}catch{return{}}}function R(e){g.set(k,JSON.stringify(e),y)}function A(e){const{dataset:o}=e.querySelector("#rls-token")||{};return w(o)}function F(e){const o=new URLSearchParams(e.location.search),r=S.reduce((c,n)=>(c[n]=o.get(`utm_${n}`)||o.get(n)||o.get(`utm_${n.toLowerCase()}`)||o.get(n.toLowerCase())||null,c),{});return w(r)}function _(e){try{return new URL(e.referrer).hostname!==e.location.hostname?{referrer:e.referrer}:{}}catch{return{}}}function $(e){const r=new URLSearchParams(e.location.search).has("dnt"),{dnt:c}=v(),n=M(e);return r||n||c}function M(e){const{navigator:o}=e;if(e.doNotTrack||o.doNotTrack||o.msDoNotTrack)return e.doNotTrack=="1"||o.doNotTrack=="yes"||o.doNotTrack=="1"||o.msDoNotTrack=="1"}function w(e={}){return S.reduce((o,r)=>{const c=(e[r]||"").trim();return c&&(o[r]=c),o},{})}return typeof window<"u"&&document.addEventListener("DOMContentLoaded",()=>{x(window)}),{collect:x,clear:p,getVisitorId:L}}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.RebillyLeadSource=t())})(this,function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)r!==`__proto__`&&(e[r]=n[r])}return e}var t={read:function(e){return e[0]===`"`&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function n(t,r){function i(n,i,a){if(typeof document<`u`){a=e({},r,a),typeof a.expires==`number`&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),n=encodeURIComponent(n).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o=``;for(var s in a)a[s]&&(o+=`; `+s,a[s]!==!0&&(o+=`=`+a[s].split(`;`)[0]));return document.cookie=n+`=`+t.write(i,n)+o}}function a(e){if(!(typeof document>`u`||arguments.length&&!e)){for(var n=document.cookie?document.cookie.split(`; `):[],r={},i=0;i<n.length;i++){var a=n[i].split(`=`),o=a.slice(1).join(`=`);try{var s=decodeURIComponent(a[0]);if(s in r||(r[s]=t.read(o,s)),e===s)break}catch{}}return e?r[e]:r}}return Object.create({set:i,get:a,remove:function(t,n){i(t,``,e({},n,{expires:-1}))},withAttributes:function(t){return n(this.converter,e({},this.attributes,t))},withConverter:function(t){return n(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}var r=n(t,{path:`/`});function i(e,t,n){return{test:t=>t===e||t.endsWith(`.${e}`),source:t,medium:n}}var a=[i(`chatgpt.com`,`chatgpt`,`ai-assistant`),i(`chat.openai.com`,`chatgpt`,`ai-assistant`),i(`perplexity.ai`,`perplexity`,`ai-assistant`),i(`claude.ai`,`claude`,`ai-assistant`),i(`gemini.google.com`,`gemini`,`ai-assistant`),i(`copilot.microsoft.com`,`copilot`,`ai-assistant`),i(`mail.google.com`,`gmail`,`email`),i(`outlook.live.com`,`outlook`,`email`),i(`outlook.office.com`,`outlook`,`email`),i(`mail.yahoo.com`,`yahoo-mail`,`email`),{test:e=>/^(www\.)?google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(e),source:`google`,medium:`organic-search`},i(`bing.com`,`bing`,`organic-search`),i(`duckduckgo.com`,`duckduckgo`,`organic-search`),i(`github.com`,`github`,`community`),i(`stackoverflow.com`,`stack-overflow`,`community`),i(`reddit.com`,`reddit`,`community`),i(`news.ycombinator.com`,`hacker-news`,`community`),i(`dev.to`,`dev-to`,`community`),i(`linkedin.com`,`linkedin`,`social`),i(`lnkd.in`,`linkedin`,`social`),i(`twitter.com`,`x-twitter`,`social`),i(`x.com`,`x-twitter`,`social`),i(`t.co`,`x-twitter`,`social`),i(`youtube.com`,`youtube`,`social`),i(`youtu.be`,`youtube`,`social`),i(`bsky.app`,`bluesky`,`social`),i(`facebook.com`,`facebook`,`social`),i(`fb.com`,`facebook`,`social`),i(`fb.me`,`facebook`,`social`),i(`instagram.com`,`instagram`,`social`),i(`tiktok.com`,`tiktok`,`social`),i(`snapchat.com`,`snapchat`,`social`),i(`pinterest.com`,`pinterest`,`social`),i(`pin.it`,`pinterest`,`social`),i(`threads.net`,`threads`,`social`),i(`threads.com`,`threads`,`social`)];function o(e){if(!e)return null;let t;try{t=new URL(e).hostname.toLowerCase()}catch{return null}let n=a.find(e=>e.test(t));return n?{source:n.source,medium:n.medium}:null}function s(e){return[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function c(){if(typeof crypto>`u`||typeof crypto.getRandomValues!=`function`)return null;let e=new Uint8Array(16);crypto.getRandomValues(e);let t=Date.now();e[0]=Math.floor(t/1099511627776)&255,e[1]=Math.floor(t/4294967296)&255,e[2]=Math.floor(t/16777216)&255,e[3]=Math.floor(t/65536)&255,e[4]=Math.floor(t/256)&255,e[5]=t&255,e[6]=e[6]&15|112,e[8]=e[8]&63|128;let n=s(e);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}var l=`rls`,u={expires:45},d=[`source`,`medium`,`campaign`,`term`,`content`,`affiliate`,`subAffiliate`,`clickId`,`salesAgent`],f=[`path`,`referrer`],p=[...f,...d];function m(e,t){let{classifyReferrer:n=!1,visitorId:r=!1,...i}=t||{},{document:a}=e;if(C(e))return h({dnt:!0}),{};let o={path:a.location.host+a.location.pathname,...b(a),...S(a),...x(e)};r&&delete o.clickId;let{leadSource:s}=_({leadSource:o},i,n,r);return s||{}}function h({dnt:e=!1}){let t={dnt:e};return e?y(t):r.remove(l,u),t}function g(){return v().leadSource?.clickId}function _(e,t,n=!1,r=!1){let i=v();if(i.dnt||e.dnt)return h({dnt:!0});h({dnt:!1});let a=i.leadSource||{},s=f.reduce((e,t)=>{let n=a[t];return n&&(e[t]=n),e},{}),l={leadSource:{...a,...T(e.leadSource),...s}};if(n){let e=l.leadSource;if(!e.source||!e.medium){let t=o(e.referrer);t&&(e.source=e.source||t.source,e.medium=e.medium||t.medium)}}if(r&&!l.leadSource.clickId){let e=c();e&&(l.leadSource.clickId=e)}return Object.assign(u,t||{}),y(l),l}function v(){let e=r.get(l);if(!e)return{};try{let t=JSON.parse(e);return t.dnt?{dnt:!0}:t}catch{return{}}}function y(e){r.set(l,JSON.stringify(e),u)}function b(e){let{dataset:t}=e.querySelector(`#rls-token`)||{};return T(t)}function x(e){let t=new URLSearchParams(e.location.search);return T(p.reduce((e,n)=>(e[n]=t.get(`utm_${n}`)||t.get(n)||t.get(`utm_${n.toLowerCase()}`)||t.get(n.toLowerCase())||null,e),{}))}function S(e){try{return new URL(e.referrer).hostname===e.location.hostname?{}:{referrer:e.referrer}}catch{return{}}}function C(e){let t=new URLSearchParams(e.location.search).has(`dnt`),{dnt:n}=v(),r=w(e);return t||r||n}function w(e){let{navigator:t}=e;if(e.doNotTrack||t.doNotTrack||t.msDoNotTrack)return e.doNotTrack==`1`||t.doNotTrack==`yes`||t.doNotTrack==`1`||t.msDoNotTrack==`1`}function T(e={}){return p.reduce((t,n)=>{let r=(e[n]||``).trim();return r&&(t[n]=r),t},{})}return typeof window<`u`&&document.addEventListener(`DOMContentLoaded`,()=>{m(window)}),{collect:m,clear:h,getVisitorId:g}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/lead-source-tracker",
3
- "version": "8.34.5",
3
+ "version": "8.34.6",
4
4
  "description": "Simple library which is used to collect and store lead source information into a cookie",
5
5
  "author": "Rebilly",
6
6
  "repository": {
@@ -18,9 +18,9 @@
18
18
  "devDependencies": {
19
19
  "@rebilly/eslint-config": "*",
20
20
  "express": "^5.1.0",
21
- "vite": "^6.4.3",
21
+ "vite": "^8.3.0",
22
22
  "vite-plugin-commonjs": "^0.10.4",
23
- "vitest": "^4.1.0"
23
+ "vitest": "^5.0.2"
24
24
  },
25
25
  "dependencies": {
26
26
  "js-cookie": "^3.0.8"