Analytics and consent SDK reference

Storefront analytics events, page views and shopper cookie choices.

Import these public values from @upstorr/theme-sdk/v1. Do not import their internal source files.

acceptAllThemeCookies

acceptAllThemeCookies(): ThemeCookieConsentPreferences | null

hasThemeAnalyticsConsent

hasThemeAnalyticsConsent(): boolean

readThemeCookieConsent

readThemeCookieConsent(): ThemeCookieConsentPreferences | null

rejectNonEssentialThemeCookies

rejectNonEssentialThemeCookies(): ThemeCookieConsentPreferences | null

THEME_COOKIE_CONSENT_CHANGED_EVENT

THEME_COOKIE_CONSENT_CHANGED_EVENT: "upstorr_theme_cookie_consent_changed"

ThemeAnalyticsEventInput

type ThemeAnalyticsEventInput = {
    eventType: ThemeAnalyticsEventType;
    eventName?: string;
    path?: string | null;
    title?: string | null;
    referrer?: string | null;
    productId?: string | null;
    orderId?: string | null;
    searchQuery?: string | null;
    revenue?: number | null;
    quantity?: number | null;
    properties?: Record<string, unknown> | null;
};

ThemeAnalyticsEventType

type ThemeAnalyticsEventType =
    | 'PAGE_VIEW'
    | 'PRODUCT_VIEW'
    | 'ADD_TO_CART'
    | 'REMOVE_FROM_CART'
    | 'ADD_TO_WISHLIST'
    | 'REMOVE_FROM_WISHLIST'
    | 'CHECKOUT_STARTED'
    | 'CHECKOUT_COMPLETED'
    | 'PURCHASE'
    | 'SEARCH'
    | 'CLICK'
    | 'FORM_SUBMIT'
    | 'CUSTOM';

ThemeCookieConsentPreferences

type ThemeCookieConsentPreferences = {
    necessary: true;
    analytics: boolean;
    marketing: boolean;
    version: 1;
    updatedAt: string;
};

trackThemeAnalyticsEvent

trackThemeAnalyticsEvent(input: ThemeAnalyticsEventInput): void

useThemeCheckoutStarted

useThemeCheckoutStarted(enabled?: boolean): void

useThemeCookieConsentChoice

useThemeCookieConsentChoice(): { hasChoice: boolean | null; acceptAll: () => boolean; rejectNonEssential: () => boolean; }

useThemePageView

useThemePageView(input?: { path?: string | null; title?: string | null; enabled?: boolean; }): void

useThemeProductView

useThemeProductView(productId: string | null | undefined, productName?: string | null): void

useThemeSearchView

useThemeSearchView(searchQuery: string | null | undefined): void

writeThemeCookieConsent

writeThemeCookieConsent(input: { analytics: boolean; marketing?: boolean; }): ThemeCookieConsentPreferences | null