KO
베타 번역

@core / pixels

1.0.1 ▾
인증됨MIT
GitHub

동의 기반 전환 추적: GA4, Meta 픽셀 + Conversions API, TikTok 픽셀 + Events API, 이벤트 중복 제거

코드파일 7개컨텍스트약 702토큰검사 통과

.genpmignore 적용 후 주입될 정확한 트리입니다. 고정 대상:

src/lib/pixels/browser.ts읽기 전용 · abb4ca2
// Parte de los píxeles sin servidor ni base de datos: la usan el navegador (`client.ts`) y el servidor.
import type { TrackedEvent } from '../contracts/index.ts';
import { toDecimalString } from '../money/index.ts';

export const META_NAMES = { view_item: 'ViewContent', add_to_cart: 'AddToCart', begin_checkout: 'InitiateCheckout', purchase: 'Purchase', lead: 'Lead' } as const;
export const TIKTOK_NAMES = { view_item: 'ViewContent', add_to_cart: 'AddToCart', begin_checkout: 'InitiateCheckout', purchase: 'CompletePayment', lead: 'SubmitForm' } as const;
export const value = (e: TrackedEvent) => ('value' in e && e.value ? e.value : null);
export const items = (e: TrackedEvent) => ('items' in e ? e.items : []);

/** Llamadas equivalentes de gtag, fbq y ttq para un evento (mismo `eventId` que el servidor). */
export function browserCalls(e: TrackedEvent) {
  const v = value(e);
  const common = { ...(v && { currency: v.currency, value: Number(toDecimalString(v)) }) };
  return {
    gtag: ['event', e.type === 'lead' ? 'generate_lead' : e.type, { ...common, event_id: e.eventId, ...(e.type === 'purchase' && { transaction_id: e.orderId }) }] as const,
    fbq: ['track', META_NAMES[e.type], { ...common, ...(items(e).length && { content_ids: items(e).map((i) => i.id), content_type: 'product' }) }, { eventID: e.eventId }] as const,
    ttq: [TIKTOK_NAMES[e.type], { ...common, event_id: e.eventId }] as const,
  };
}

@core/pixels 신고

패키지를 신고하려면 GitHub로 로그인하세요.