Add audit analytics and campaign metrics
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { ArrowRight, CheckCircle2, ExternalLink } from "lucide-react";
|
||||
import { CheckCircle2 } from "lucide-react";
|
||||
|
||||
import type { PublicAuditRenderState } from "@/lib/audits/public-audit-types";
|
||||
import { RybbitTracking } from "./rybbit-tracking";
|
||||
import { PublicAuditScreenshot } from "./public-audit-screenshot";
|
||||
import { TrackedPublicAuditLink } from "./tracked-public-audit-link";
|
||||
|
||||
type PublicAuditPageProps = {
|
||||
audit: Extract<PublicAuditRenderState, { kind: "published" }>["audit"];
|
||||
@@ -10,6 +12,7 @@ type PublicAuditPageProps = {
|
||||
export function PublicAuditPage({ audit }: PublicAuditPageProps) {
|
||||
return (
|
||||
<main className="min-h-dvh bg-slate-50 text-slate-950">
|
||||
<RybbitTracking domain={audit.domain} />
|
||||
<section className="border-b border-slate-200 bg-white">
|
||||
<div className="mx-auto grid min-h-[72dvh] w-full max-w-6xl content-center gap-10 px-6 py-14 md:grid-cols-[minmax(0,1.1fr)_minmax(320px,0.9fr)] md:px-8">
|
||||
<div className="max-w-3xl">
|
||||
@@ -105,17 +108,11 @@ export function PublicAuditPage({ audit }: PublicAuditPageProps) {
|
||||
</p>
|
||||
</div>
|
||||
{audit.finalOffer.ctaHref ? (
|
||||
<a
|
||||
<TrackedPublicAuditLink
|
||||
domain={audit.domain}
|
||||
href={audit.finalOffer.ctaHref}
|
||||
className="mt-6 inline-flex h-10 items-center justify-center gap-2 rounded-lg bg-slate-950 px-4 text-sm font-semibold text-white transition hover:bg-slate-800 md:mt-0"
|
||||
>
|
||||
{audit.finalOffer.ctaLabel ?? "Audit besprechen"}
|
||||
{audit.finalOffer.ctaHref.startsWith("/") ? (
|
||||
<ArrowRight className="h-4 w-4" aria-hidden />
|
||||
) : (
|
||||
<ExternalLink className="h-4 w-4" aria-hidden />
|
||||
)}
|
||||
</a>
|
||||
label={audit.finalOffer.ctaLabel ?? "Audit besprechen"}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
27
components/public-audit/rybbit-tracking.tsx
Normal file
27
components/public-audit/rybbit-tracking.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import Script from "next/script";
|
||||
|
||||
type RybbitTrackingProps = {
|
||||
domain: string;
|
||||
};
|
||||
|
||||
export function RybbitTracking({ domain }: RybbitTrackingProps) {
|
||||
const siteId = process.env.NEXT_PUBLIC_RYBBIT_SITE_ID?.trim();
|
||||
if (!siteId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const apiUrl = process.env.RYBBIT_API_URL?.trim() || "https://app.rybbit.io";
|
||||
const src = `${apiUrl.replace(/\/$/, "")}/api/script.js`;
|
||||
|
||||
return (
|
||||
<Script
|
||||
async
|
||||
data-site-id={siteId}
|
||||
data-domain={domain}
|
||||
defer
|
||||
id="rybbit-public-audit"
|
||||
src={src}
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
);
|
||||
}
|
||||
51
components/public-audit/tracked-public-audit-link.tsx
Normal file
51
components/public-audit/tracked-public-audit-link.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import { ArrowRight, ExternalLink } from "lucide-react";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
rybbit?: {
|
||||
event?: (name: string, properties?: Record<string, string | number>) => void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type TrackedPublicAuditLinkProps = {
|
||||
href: string;
|
||||
label: string;
|
||||
domain: string;
|
||||
};
|
||||
|
||||
export function TrackedPublicAuditLink({
|
||||
href,
|
||||
label,
|
||||
domain,
|
||||
}: TrackedPublicAuditLinkProps) {
|
||||
const isInternal = href.startsWith("/");
|
||||
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
className="mt-6 inline-flex h-10 items-center justify-center gap-2 rounded-lg bg-slate-950 px-4 text-sm font-semibold text-white transition hover:bg-slate-800 md:mt-0"
|
||||
onClick={() => {
|
||||
window.rybbit?.event?.("audit_cta_click", {
|
||||
domain,
|
||||
target: isInternal ? "cta" : "outbound_cta",
|
||||
});
|
||||
if (!isInternal) {
|
||||
window.rybbit?.event?.("audit_website_link_click", {
|
||||
domain,
|
||||
href,
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
{isInternal ? (
|
||||
<ArrowRight className="h-4 w-4" aria-hidden />
|
||||
) : (
|
||||
<ExternalLink className="h-4 w-4" aria-hidden />
|
||||
)}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user