clipwright/dashboard/src/lib/analytics.js
pedro-bento ace54c6e77
Some checks are pending
CI / backend-tests (push) Waiting to run
CI / frontend-build (push) Waiting to run
chore: rename OpenShorts to Clipwright
- Rebrand all text, package/CLI (clipwright_cli), env vars (CLIPWRIGHT_*),
  localStorage keys, Docker container names and webhook header
- Rename/relocate assets, skills/, n8n examples, font map; delete dead MCP
  metadata (server.json, glama.json) and generated egg-info
- Canonical site URL -> https://git.pbento.pt/pedro-bento/clipwright
- Preserve fork provenance (upstream OpenShorts attribution in README/NOTICE/LICENSE)
2026-10-04 18:07:07 +01:00

29 lines
1.4 KiB
JavaScript

import { allows } from './consent';
// Lightweight custom-event helper (OpenPanel).
//
// The hosted git.pbento.pt/pedro-bento/clipwright build loads OpenPanel (see index.html), which
// exposes `window.op`. Self-hosted builds, ad-blockers or offline dev simply
// won't have it — every call here is a safe no-op in that case, so analytics
// can never break the app or leak into the open-source experience.
//
// Events (name — meaning):
// - SocialNudgeSeen — post-generation "connect socials" banner rendered
// - SocialNudgeConnect — its connect button clicked (opens the Postiz UI)
// - SocialNudgeDismissed — its X clicked (persisted, never shown again)
// - ClipTutorialStarted — first-login tutorial: user hit Start
// - ClipTutorialSkipped — first-login tutorial dismissed (intro or coach)
// - ClipTutorialCompleted— first Clip Generator job finished with clips
export function track(event, options) {
try {
// `op` is a queueing stub until consent loads op1.js, so a call made before
// the visitor accepted would be flushed the moment they did. Check first.
if (!allows('analytics')) return;
if (typeof window !== 'undefined' && typeof window.op === 'function') {
const props = (options && options.props) || {};
window.op('track', event, props);
}
} catch (_) {
/* analytics must never throw into the app */
}
}