@stacksjs/analytics 0.74.47 → 0.74.50
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/capture.js +1 -1
- package/package.json +3 -3
package/dist/capture.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{db,sqlDateTime}from"@stacksjs/database";const ASSET_EXT=/\.(?:css|js|mjs|map|png|jpe?g|gif|webp|avif|svg|ico|woff2?|ttf|otf|eot|txt|xml|json|webmanifest|mp[34]|webm|pdf|zip)$/i;export function isPageviewRequest(method,pathname,headers){if(method!=="GET")return!1;if(ASSET_EXT.test(pathname))return!1;if(pathname.startsWith("/api/")||pathname.startsWith("/__")||pathname.startsWith("/_"))return!1;const accept=headers.get("accept")??"";if(accept&&!accept.includes("text/html")&&!accept.includes("*/*"))return!1;const agent=(headers.get("user-agent")??"").toLowerCase();if(!agent)return!1;if(/bot|crawler|spider|preview|monitor|curl|wget|python-requests|headless/.test(agent))return!1;return!0}export function classifyAgent(userAgent){const agent=userAgent.toLowerCase(),device=/ipad|tablet/.test(agent)?"tablet":/mobi|iphone|android/.test(agent)?"mobile":"desktop",browser=agent.includes("edg/")?"edge":agent.includes("opr/")||agent.includes("opera")?"opera":agent.includes("firefox/")?"firefox":agent.includes("chrome/")||agent.includes("crios/")?"chrome":agent.includes("safari/")?"safari":"other";return{device,browser}}export function referrerHost(referrer,ownHost){if(!referrer)return null;try{const host=new URL(referrer).host.toLowerCase();return host&&host!==ownHost.toLowerCase()?host:null}catch{return null}}export async function recordPageview(req){try{const url=new URL(req.url);if(!isPageviewRequest(req.method,url.pathname,req.headers))return;const agent=req.headers.get("user-agent")??"",{device,browser}=classifyAgent(agent),now=sqlDateTime(new Date);await db.insertInto("analytics_events").values({name:"pageview",category:"web",path:url.pathname,properties:JSON.stringify({host:req.headers.get("x-forwarded-host")?.split(",")[0]?.trim()||url.host,referrer:referrerHost(req.headers.get("referer"),url.host),device,browser}),created_at:now,updated_at:now}).execute()}catch{}}
|
|
1
|
+
import{db,sqlDateTime}from"@stacksjs/database/runtime";const ASSET_EXT=/\.(?:css|js|mjs|map|png|jpe?g|gif|webp|avif|svg|ico|woff2?|ttf|otf|eot|txt|xml|json|webmanifest|mp[34]|webm|pdf|zip)$/i;export function isPageviewRequest(method,pathname,headers){if(method!=="GET")return!1;if(ASSET_EXT.test(pathname))return!1;if(pathname.startsWith("/api/")||pathname.startsWith("/__")||pathname.startsWith("/_"))return!1;const accept=headers.get("accept")??"";if(accept&&!accept.includes("text/html")&&!accept.includes("*/*"))return!1;const agent=(headers.get("user-agent")??"").toLowerCase();if(!agent)return!1;if(/bot|crawler|spider|preview|monitor|curl|wget|python-requests|headless/.test(agent))return!1;return!0}export function classifyAgent(userAgent){const agent=userAgent.toLowerCase(),device=/ipad|tablet/.test(agent)?"tablet":/mobi|iphone|android/.test(agent)?"mobile":"desktop",browser=agent.includes("edg/")?"edge":agent.includes("opr/")||agent.includes("opera")?"opera":agent.includes("firefox/")?"firefox":agent.includes("chrome/")||agent.includes("crios/")?"chrome":agent.includes("safari/")?"safari":"other";return{device,browser}}export function referrerHost(referrer,ownHost){if(!referrer)return null;try{const host=new URL(referrer).host.toLowerCase();return host&&host!==ownHost.toLowerCase()?host:null}catch{return null}}export async function recordPageview(req){try{const url=new URL(req.url);if(!isPageviewRequest(req.method,url.pathname,req.headers))return;const agent=req.headers.get("user-agent")??"",{device,browser}=classifyAgent(agent),now=sqlDateTime(new Date);await db.insertInto("analytics_events").values({name:"pageview",category:"web",path:url.pathname,properties:JSON.stringify({host:req.headers.get("x-forwarded-host")?.split(",")[0]?.trim()||url.host,referrer:referrerHost(req.headers.get("referer"),url.host),device,browser}),created_at:now,updated_at:now}).execute()}catch{}}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/analytics",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.50",
|
|
6
6
|
"description": "Stacks Analytics. Privacy-friendly.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"prepublishOnly": "bun run build"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@stacksjs/database": "0.74.
|
|
55
|
-
"@stacksjs/types": "0.74.
|
|
54
|
+
"@stacksjs/database": "0.74.50",
|
|
55
|
+
"@stacksjs/types": "0.74.50"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"better-dx": "^0.2.24"
|