@rebilly/lead-source-tracker 8.34.4 → 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.
- package/dist/build.js +1 -1
- package/package.json +3 -3
package/dist/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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.
|
|
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": "^
|
|
21
|
+
"vite": "^8.3.0",
|
|
22
22
|
"vite-plugin-commonjs": "^0.10.4",
|
|
23
|
-
"vitest": "^
|
|
23
|
+
"vitest": "^5.0.2"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"js-cookie": "^3.0.8"
|