@stacksjs/analytics 0.70.23 → 0.70.26

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/index.js +56 -1
  2. package/package.json +10 -4
package/dist/index.js CHANGED
@@ -1 +1,56 @@
1
- var o=1;export{o as fathomWip};
1
+ var B=1;function F(m){if(!m.siteId||!m.apiEndpoint)return"";let x=q(m.siteId),W=q(m.apiEndpoint),j=m.honorDnt?'if(n.doNotTrack==="1")return;':"",w=m.trackHashChanges?"w.addEventListener('hashchange',pv);":"",y=m.trackOutboundLinks?`
2
+ d.addEventListener('click',function(e){
3
+ var a=e.target.closest('a');
4
+ if(a&&a.hostname!==location.hostname){
5
+ t('outbound',{url:a.href});
6
+ }
7
+ });`:"";return`<!-- Stacks Self-Hosted Analytics -->
8
+ <script data-site="${x}" data-api="${W}" defer>
9
+ (function(){
10
+ 'use strict';
11
+ var d=document,w=window,n=navigator,s=d.currentScript;
12
+ var site=s.dataset.site,api=s.dataset.api;
13
+ ${j}
14
+ var q=[],sid=Math.random().toString(36).slice(2);
15
+ function t(e,p){
16
+ var x=new XMLHttpRequest();
17
+ x.open('POST',api+'/collect',true);
18
+ x.setRequestHeader('Content-Type','application/json');
19
+ // Strip the URL's query string before sending. location.href includes
20
+ // tokens / session IDs / search terms that shouldn't reach the
21
+ // analytics backend. Same goes for document.referrer when it points
22
+ // back to our own domain (path is fine, query is not).
23
+ var safeUrl=location.origin+location.pathname+location.hash;
24
+ var safeRef=d.referrer?d.referrer.split('?')[0]:'';
25
+ x.send(JSON.stringify({
26
+ s:site,sid:sid,e:e,p:p||{},
27
+ u:safeUrl,r:safeRef,t:d.title,
28
+ sw:screen.width,sh:screen.height
29
+ }));
30
+ }
31
+ function pv(){t('pageview');}
32
+ ${w}
33
+ ${y}
34
+ if(d.readyState==='complete')pv();
35
+ else w.addEventListener('load',pv);
36
+ w.stacksAnalytics={track:function(n,v){t('event',{name:n,value:v});}};
37
+ })();
38
+ </script>`}function G(m){if(!m.siteId||!m.apiEndpoint)return[];return[["script",{"data-site":m.siteId,"data-api":m.apiEndpoint,defer:"",innerHTML:z(m)}]]}function z(m){let x=m.honorDnt?'if(n.doNotTrack==="1")return;':"",W=m.trackHashChanges?"w.addEventListener('hashchange',pv);":"",j=m.trackOutboundLinks?"d.addEventListener('click',function(e){var a=e.target.closest('a');if(a&&a.hostname!==location.hostname){t('outbound',{url:a.href});}});":"";return`(function(){
39
+ 'use strict';
40
+ var d=document,w=window,n=navigator,s=d.currentScript;
41
+ var site=s.dataset.site,api=s.dataset.api;
42
+ ${x}
43
+ var q=[],sid=Math.random().toString(36).slice(2);
44
+ function t(e,p){
45
+ var x=new XMLHttpRequest();
46
+ x.open('POST',api+'/collect',true);
47
+ x.setRequestHeader('Content-Type','application/json');
48
+ var safeUrl=location.origin+location.pathname+location.hash;var safeRef=d.referrer?d.referrer.split('?')[0]:'';x.send(JSON.stringify({s:site,sid:sid,e:e,p:p||{},u:safeUrl,r:safeRef,t:d.title,sw:screen.width,sh:screen.height}));
49
+ }
50
+ function pv(){t('pageview');}
51
+ ${W}
52
+ ${j}
53
+ if(d.readyState==='complete')pv();
54
+ else w.addEventListener('load',pv);
55
+ w.stacksAnalytics={track:function(n,v){t('event',{name:n,value:v});}};
56
+ })();`}function q(m){return m.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}export{G as getSelfHostedAnalyticsHead,F as generateSelfHostedScript,B as fathomWip};
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@stacksjs/analytics",
3
3
  "type": "module",
4
- "version": "0.70.23",
4
+ "version": "0.70.26",
5
5
  "description": "Stacks Analytics. Privacy-friendly.",
6
6
  "author": "Chris Breuer",
7
- "contributors": ["Chris Breuer <chris@stacksjs.org>"],
7
+ "contributors": [
8
+ "Chris Breuer <chris@stacksjs.com>"
9
+ ],
8
10
  "license": "MIT",
9
11
  "funding": "https://github.com/sponsors/chrisbbreuer",
10
12
  "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/analytics#readme",
@@ -31,18 +33,22 @@
31
33
  ],
32
34
  "exports": {
33
35
  ".": {
36
+ "bun": "./src/index.ts",
34
37
  "import": "./dist/index.js"
35
38
  }
36
39
  },
37
40
  "module": "dist/index.js",
38
41
  "types": "dist/index.d.ts",
39
- "files": ["README.md", "dist"],
42
+ "files": [
43
+ "README.md",
44
+ "dist"
45
+ ],
40
46
  "scripts": {
41
47
  "build": "bun build.ts",
42
48
  "typecheck": "bun tsc --noEmit",
43
49
  "prepublishOnly": "bun run build"
44
50
  },
45
51
  "devDependencies": {
46
- "@stacksjs/development": "0.70.22"
52
+ "better-dx": "^0.2.12"
47
53
  }
48
54
  }