fix: 🐛 Fix incorrect Plausible loading

This commit is contained in:
Jesse Wierzbinski 2025-01-01 01:10:18 +01:00
parent e754c2ff6a
commit c6d694151d
No known key found for this signature in database
4 changed files with 6 additions and 8 deletions

View file

@ -1,7 +1,6 @@
import glob from "fast-glob"; import glob from "fast-glob";
import type { Metadata } from "next"; import type { Metadata } from "next";
import PlausibleProvider from "next-plausible";
import { Layout } from "../components/Layout"; import { Layout } from "../components/Layout";
import type { Section } from "../components/SectionProvider"; import type { Section } from "../components/SectionProvider";
import { Providers } from "./providers"; import { Providers } from "./providers";
@ -47,12 +46,11 @@ export default async function RootLayout({
<html lang="en" className="h-full" suppressHydrationWarning={true}> <html lang="en" className="h-full" suppressHydrationWarning={true}>
<head> <head>
<link rel="icon" href="/favicon.png" type="image/png" /> <link rel="icon" href="/favicon.png" type="image/png" />
<PlausibleProvider <script
domain="logs.cpluspatch.com" defer={true}
customDomain="https://logs.cpluspatch.com" data-api="https://logs.cpluspatch.com/api/event"
trackOutboundLinks={true} data-domain="versia.pub"
trackLocalhost={false} src="/pl.js"
selfHosted={true}
/> />
</head> </head>
<body className="flex min-h-full bg-white antialiased dark:bg-zinc-900"> <body className="flex min-h-full bg-white antialiased dark:bg-zinc-900">

BIN
bun.lockb

Binary file not shown.

View file

@ -33,7 +33,6 @@
"mdast-util-to-string": "^4.0.0", "mdast-util-to-string": "^4.0.0",
"mdx-annotations": "^0.1.4", "mdx-annotations": "^0.1.4",
"next": "^14.2.13", "next": "^14.2.13",
"next-plausible": "^3.12.4",
"next-themes": "^0.3.0", "next-themes": "^0.3.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",

1
public/pl.js Normal file
View file

@ -0,0 +1 @@
!function(){"use strict";var l=window.location,i=window.document,t=i.currentScript,r=t.getAttribute("data-api")||new URL(t.src).origin+"/api/event",o=t.getAttribute("data-domain");function s(t,e){t&&console.warn("Ignoring Event: "+t),e&&e.callback&&e.callback()}function e(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(l.hostname)||"file:"===l.protocol)return s("localhost",e);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__plausible)return s(null,e);try{if("true"===window.localStorage.plausible_ignore)return s("localStorage flag",e)}catch(t){}var a={},n=(a.n=t,a.u=l.href,a.d=o,a.r=i.referrer||null,e&&e.meta&&(a.m=JSON.stringify(e.meta)),e&&e.props&&(a.p=e.props),new XMLHttpRequest);n.open("POST",r,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(a)),n.onreadystatechange=function(){4===n.readyState&&e&&e.callback&&e.callback({status:n.status})}}var a=window.plausible&&window.plausible.q||[];window.plausible=e;for(var n,p=0;p<a.length;p++)e.apply(this,a[p]);function c(){n!==l.pathname&&(n=l.pathname,e("pageview"))}function u(){c()}var d,t=window.history;t.pushState&&(d=t.pushState,t.pushState=function(){d.apply(this,arguments),u()},window.addEventListener("popstate",u)),"prerender"===i.visibilityState?i.addEventListener("visibilitychange",function(){n||"visible"!==i.visibilityState||c()}):c();var f=1;function w(t){var e,a,n,i,r;function o(){n||(n=!0,window.location=a.href)}"auxclick"===t.type&&t.button!==f||((e=function(t){for(;t&&(void 0===t.tagName||!(e=t)||!e.tagName||"a"!==e.tagName.toLowerCase()||!t.href);)t=t.parentNode;var e;return t}(t.target))&&e.href&&e.href.split("?")[0],(r=e)&&r.href&&r.host&&r.host!==l.host&&(r=t,t={name:"Outbound Link: Click",props:{url:(a=e).href}},n=!1,!function(t,e){if(!t.defaultPrevented)return e=!e.target||e.target.match(/^_(self|parent|top)$/i),t=!(t.ctrlKey||t.metaKey||t.shiftKey)&&"click"===t.type,e&&t}(r,a)?(i={props:t.props},plausible(t.name,i)):(i={props:t.props,callback:o},plausible(t.name,i),setTimeout(o,5e3),r.preventDefault())))}i.addEventListener("click",w),i.addEventListener("auxclick",w)}();