OpinlySDK

Events & tracking

Send events with track(): standard events, custom events, and revenue.

track() on the @opinly/backend client records a server-side event. The name can be anything: pick a standard event if one fits, or make your own.

It runs with your secret sk- key. Page views, form fills, and identify are already handled in the browser by the pixel (publishable pk- key), so you don't send those yourself.

track

import { createOpinlyClient } from '@opinly/backend'

const opinly = createOpinlyClient()

await opinly.track('sign_up', { method: 'google' }, { email: 'user@example.com' })

await opinly.track(
  'purchase',
  { value: 49.0, currency: 'USD' },
  { externalEventId: 'order_123', email: 'user@example.com' },
)
Argument
eventThe event name, standard or custom.
propertiesData to attach. Revenue events need value (major units) and currency.
opts.externalEventIdDedup key. Two calls with the same id become one event, so retries are safe.
opts.emailTies the event to a visitor. We hash it; the raw email is never stored.
opts.anonIdThe visitor's Opinly id, if you captured it in the browser.

Standard events

Any name works, but these are the ones worth knowing. They line up with GA4, Meta, and Segment, so the data maps over without translation. Revenue comes from value + currency; every other property is stored as-is.

EventWhen to send itCommon propertiesRevenue
purchaseOrder completedvalue, currency, transaction_id, itemsyes
refundOrder refundedvalue, currency, transaction_idyes
add_to_cartItem added to cartvalue, currency, items
remove_from_cartItem removedvalue, currency, items
begin_checkoutCheckout startedvalue, currency, items, coupon
add_payment_infoPayment details enteredvalue, currency, payment_type
view_itemProduct viewedvalue, currency, items
searchSearch runsearch_term
sign_upAccount createdmethod
loginUser logged inmethod
generate_leadLead or contact submittedvalue, currency
start_trialTrial startedplan, value, currency
subscribeSubscription startedplan, interval, value, currency

Only purchase and refund become revenue. A value on anything else stays a plain property.

Want autocomplete? Import the list:

import { STANDARD_EVENTS, type StandardEvent } from '@opinly/backend'

trackPurchase

Shorthand for a purchase:

await opinly.trackPurchase({
  orderId: 'order_123',
  value: 49.0,
  currency: 'USD',
  email: 'user@example.com',
})

Reserved names

The pixel fires these itself, so the API rejects them with a 400:

page_view, page_leave, click, form_submit, identify, session_start, scroll, and anything starting with $.