Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analytics] Add OneDollarStats collector #958

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions analytics/components/OneDollarStats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Head } from "$fresh/runtime.ts";

export interface Props {
/**
* @description collector address to use
*/
collectorAddress?: string;
}

const trackerOriginal =
'"use strict";(()=>{function r(e){return e.getAttribute("data-hash-routing")!==null}function s(e){console.warn(`Ignoring event: ${e}`)}function c(e,t){if(navigator.sendBeacon!==void 0){if(navigator.sendBeacon(e,JSON.stringify(t)))return;console.warn("sendBeacon() didnt queue the request, falling back to fetch()")}fetch(e,{body:JSON.stringify(t),headers:{"Content-Type":"application/json"},keepalive:!0,method:"POST"}).catch(i=>console.error(`fetch() failed: ${i.message}`))}async function n(){if(!o&&n.lastPage===location.pathname)return s("Pathname has not changed");n.lastPage=location.pathname;let e=new URL(location.href),t=document.referrer?new URL(document.referrer):void 0;t&&(t.search="");let i={t:"PageView",u:e.href,h:o,r:t&&t.hostname!==e.hostname?t.href:void 0};c("COLLECTOR_ADDRESS",i)}(t=>t.lastPage=null)(n||={});var u=document.currentScript,o=r(u);if(window.history.pushState){let e=window.history.pushState;window.history.pushState=function(t,i,a){e.apply(this,[t,i,a]),n()},window.addEventListener("popstate",n)}document.visibilityState!=="visible"?document.addEventListener("visibilitychange",()=>{!n.lastPage&&document.visibilityState==="visible"&&n()}):n();})();';

function Component({ collectorAddress }: Props) {
const collector = collectorAddress ?? "https://collector.deco.cx/events";
const tracker = trackerOriginal.replace("COLLECTOR_ADDRESS", collector);

return (
<Head>
<link rel="dns-prefetch" href="https://collector.deco.cx/events" />
<link
rel="preconnect"
href="https://collector.deco.cx/events"
crossOrigin="anonymous"
/>
<script
dangerouslySetInnerHTML={{
__html: tracker,
}}
/>
</Head>
);
}
export default Component;
2 changes: 2 additions & 0 deletions analytics/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import * as $$$0 from "./loaders/DecoAnalyticsScript.ts";
import * as $$$$$$0 from "./sections/Analytics/DecoAnalytics.tsx";
import * as $$$$$$1 from "./sections/Analytics/OneDollarStats.tsx";

const manifest = {
"loaders": {
"analytics/loaders/DecoAnalyticsScript.ts": $$$0,
},
"sections": {
"analytics/sections/Analytics/DecoAnalytics.tsx": $$$$$$0,
"analytics/sections/Analytics/OneDollarStats.tsx": $$$$$$1,
},
"name": "analytics",
"baseUrl": import.meta.url,
Expand Down
14 changes: 14 additions & 0 deletions analytics/sections/Analytics/OneDollarStats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Plausible, { type Props } from "../../components/OneDollarStats.tsx";

function Section(props: Props) {
return <Plausible {...props} />;
}

export const Preview = () => (
<iframe
style="width: 100%; height: 100vh; border: none;"
src="https://onedollarstats.com/"
/>
);

export default Section;
Loading