RTN Docs

Web SDK · v0.6.0

API Reference

Method signatures and behavior for every public RTN Web SDK 0.6.0 API.

Public methods never throw. Invalid input, such as track(undefined) or productViewed(null), is ignored and logged when debug: true. With the legacy queued snippet, up to 100 calls made before the script loads are buffered and replayed after init; with the recommended two-tag snippet rtn is ready before your code runs; with an async loader, call methods from its onload handler.

Setup

rtn.init(writeKey, options?)

Initializes the SDK. Call it once after the script loads. See Configuration for options.

rtn.ready(callback)

Runs callback once the SDK has loaded. With the legacy queued snippet it can be called before the script finishes loading.

rtn.version

The loaded SDK version, for example '0.6.0'.

rtn.setConsent(state)

Sets the analytics decision to 'granted', 'denied', or 'pending'. Stored and shared with other tabs.

rtn.setConsentPurpose(purpose, state) / rtn.getConsentPurpose(purpose)

Manages a purpose-level decision. purpose is 'analytics', 'personalization', 'advertising', 'audiences', or 'replay'. See Consent.

rtn.pause() / rtn.resume()

Stops and restarts collection and delivery without deleting identities or queued events. Calls made while paused are dropped.

Identity

rtn.identify(userId, traits?) / rtn.identify(traits)

Associates events with a known customer. For a guest without a customer ID, pass only traits with email or phone.

rtn.reset()

Clears the known user and starts a new anonymous identity. Call it at sign-out.

rtn.getAnonymousId()

Returns the browser's anonymous ID, or null without consent.

rtn.decorateLink(url) → Promise<string>

Adds a one-time linker token to a URL on an allowlisted domain. See Cross-Domain Identity.

rtn.acceptLinkerToken() → Promise<boolean>

Resolves true once an incoming linker token was exchanged and the identity carried over. A token in the address on page load is removed and exchanged automatically during init; call this only to await that result, or after an SPA navigation added a token.

Events

rtn.track(event, properties?)

Records a custom event. event must be lowercase snake_case. See Custom Events.

rtn.page(properties?)

Records a page view. Automatic by default; see Automatic Tracking.

Ecommerce helpers

  • rtn.productViewed(product)
  • rtn.productAddedToCart(product)
  • rtn.productRemovedFromCart(product)
  • rtn.cartViewed(cart)
  • rtn.checkoutStarted(cart)
  • rtn.orderCompleted(order)
  • rtn.signedUp(method?)
  • rtn.loggedIn(method?)
  • rtn.searched(query)

See Ecommerce Events for required fields.

rtn.trackDownload(elementOrUrl) / rtn.trackOutboundLink(elementOrUrl)

Explicitly records file_downloaded or outbound_link_clicked for an anchor element or URL.

rtn.register(properties) / rtn.unregister(key)

Adds or removes properties that are attached to every following track and page event on the page. Event properties win.

Attribution

rtn.getAttribution()

Returns the local { first_touch, last_touch } snapshot, or null without consent.

rtn.waitForAttribution({ timeoutMs? }) → Promise<Attribution>

Resolves with server-confirmed attribution, or with the local snapshot after timeoutMs (default 2000). See Attribution.

Web push

rtn.subscribeToPush({ vapidPublicKey, serviceWorkerPath? }) → Promise<PushPermission>

Asks for notification permission (when undecided), subscribes the browser and sends push_subscribed. Call it from a click. See Web Push.

rtn.unsubscribeFromPush({ serviceWorkerPath? }) → Promise<void>

Removes the subscription and sends push_unsubscribed.

rtn.getPushPermission() → PushPermission

'granted', 'denied', 'default', or 'unsupported'.

Delivery

rtn.flush() → Promise<void>

Immediately attempts to send queued events. Useful before a controlled redirect, such as a payment page.

await rtn.flush();
location.href = paymentUrl;

client.destroy()

Bundler clients only. Removes listeners; every later call becomes a permanent no-op.

On this page