Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

1.7 KB
Raw Blame
"use client";

import { useOpenPanel } from "@openpanel/nextjs";
import { useCallback } from "react";

export type PreviewSurface =
  | "hero"
  | "bento"
  | "landing_code_showcase"
  | "docs";

export type CtaId =
  | "hero_start"
  | "hero_showcases"
  | "hero_saas_typography_badge"
  | "hero_motion_graphics_badge"
  | "hero_motion_pack_badge"
  | "hero_templates_badge"
  | "how_it_works_setup"
  | "final_cta"
  | "github_header"
  | "studio_bar"
  | "footer_external";

type AnalyticsEvents = {
  install_command_copied: {
    component: string;
    package_manager: "pnpm" | "npm" | "yarn" | "bun" | "prompt";
    surface: "docs" | "landing" | "bento";
  };
  install_prompt_opened: {
    component: string;
    agent: "claude" | "chatgpt" | "cursor";
    surface: "docs";
  };
  preview_played: {
    component: string;
    surface: PreviewSurface;
    trigger: "click" | "hover";
  };
  preview_paused: {
    component: string;
    surface: PreviewSurface;
  };
  component_customized: {
    component: string;
    prop: string;
  };
  customized_link_shared: {
    component: string;
  };
  docs_markdown_copied: {
    page: string;
  };
  customizer_reset: {
    component: string;
  };
  cta_clicked: {
    cta: CtaId;
    destination: string;
  };
  docs_component_viewed: {
    component: string;
  };
  studio_install_clicked: {
    component: string;
  };
  studio_drag_started: {
    component: string;
  };
};

export function useTrackEvent() {
  const op = useOpenPanel();
  return useCallback(
    <E extends keyof AnalyticsEvents>(
      event: E,
      ...args: AnalyticsEvents[E] extends Record<string, never>
        ? []
        : [AnalyticsEvents[E]]
    ) => {
      op.track(event, args[0] as Record<string, unknown> | undefined);
    },
    [op],
  );
}