Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Stop animating in the final CTA (#3053)

Luke Vellac7f3486bd0fe
diff --git a/apps/landing/src/components/home/capture-on-view.tsx b/apps/landing/src/components/home/capture-on-view.tsx
new file mode 100644
index 000000000..3c44e0fef
--- /dev/null
+++ b/apps/landing/src/components/home/capture-on-view.tsx
@@ -0,0 +1,45 @@
+"use client";
+
+import { posthog } from "@rallly/posthog/client";
+import type { ReactNode } from "react";
+import * as React from "react";
+
+/**
+ * Fires a PostHog event the first time its contents scroll into view.
+ *
+ * Deliberately not a ratio threshold: a block taller than twice the viewport
+ * can never reach a 0.5 ratio, and one taller than the viewport can never
+ * reach 1, so either would silently stop reporting on small screens. Insetting
+ * the root bottom edge instead means "scrolled meaningfully into view" holds
+ * at any element height.
+ */
+export function CaptureOnView({
+ event,
+ children,
+}: {
+ event: string;
+ children: ReactNode;
+}) {
+ const ref = React.useRef<HTMLDivElement>(null);
+
+ React.useEffect(() => {
+ const el = ref.current;
+ if (!el) {
+ return;
+ }
+ const observer = new IntersectionObserver(
+ ([entry]) => {
+ if (!entry.isIntersecting) {
+ return;
+ }
+ observer.disconnect();
+ posthog.capture(event);
+ },
+ { rootMargin: "0px 0px -150px 0px" },
+ );
+ observer.observe(el);
+ return () => observer.disconnect();
+ }, [event]);
+
+ return <div ref={ref}>{children}</div>;
+}
diff --git a/apps/landing/src/components/home/cta.tsx b/apps/landing/src/components/home/cta.tsx
index 1c8b74979..38a3f58b9 100644
--- a/apps/landing/src/components/home/cta.tsx
+++ b/apps/landing/src/components/home/cta.tsx
@@ -1,7 +1,7 @@
import { cn } from "@rallly/ui";
import type * as React from "react";
+import { CaptureOnView } from "@/components/home/capture-on-view";
import { CtaButton } from "@/components/home/cta-button";
-import { FadeIn } from "@/components/home/fade-in";
import { handwritten } from "@/fonts/handwritten";
export function Cta({
@@ -16,7 +16,7 @@ export function Cta({
hint: React.ReactNode;
}) {
return (
- <FadeIn amount="all" captureOnEnter="landing:final_cta_view">
+ <CaptureOnView event="landing:final_cta_view">
<div className="grid gap-4 text-center sm:grid-cols-2 sm:gap-6 sm:text-left">
<h2 className="text-balance font-medium text-2xl text-gray-800 leading-tight tracking-tight sm:text-4xl">
{title}
@@ -39,6 +39,6 @@ export function Cta({
{hint}
</p>
</div>
- </FadeIn>
+ </CaptureOnView>
);
}