Skip to content

SDK reference

Referrals

Where your users came from, for PlayStep Referrals. The @axceera/playstep-referrals add-on and its script tag.

@axceera/playstep-referrals tells PlayStep where each user came from: a partner's PlayStep link, a promo code, UTM tags or the site that sent them. It is an add-on, separate from @axceera/playstep, so apps that don't use Referrals download none of it. It is about 2 KB gzipped and has no dependencies.

On a marketing site it remembers the visit in a first-party cookie on your root domain, so a visitor who lands on acme.com from go.playstep.app/alice is still known on app.acme.com. When your app identifies the user, it sends their touches once, with the user id hashed exactly as the core SDK hashes it. The raw id never leaves the browser.

Install with npm

Terminal
npm install @axceera/playstep @axceera/playstep-referrals
TypeScript
import { playstep } from '@axceera/playstep'
import { referrals } from '@axceera/playstep-referrals'

playstep.init({ appKey: 'ps_pub_prod_your_key' })
const ref = referrals(playstep, { appKey: 'ps_pub_prod_your_key' })

// Later, as usual: the add-on is listening.
playstep.identify(user.id, { email: user.email })

referrals(playstep, options) wraps the core's identify and reset in place, so every caller is covered, the React provider included. Calling it twice keeps the first add-on. On a page without the core (a marketing site), pass null: referrals(null, { appKey }).

OptionWhat it does
appKeyYour publishable key, the same one PlayStep is set up with.
appDomainsYour app's other domains, such as ['app.acme.io'] when the site is acme.com. A cookie can't follow a visitor there, so links to them carry the ref instead.
consent'required' remembers nothing until you call ref.consent(true). Default 'granted'.
apiPlayStep's API, for staging or local development.

When the app identifies a user, the add-on tells PlayStep where they came from, once per user and browser. A user who came with no link, code or campaign counts as direct, so Sources covers every signed-in user.

identify traits stay as they are. If they include email, the add-on sends its SHA-256 (trimmed and lower-cased), never the address. PlayStep uses it only to stop partners getting credit for signing up themselves.

Install with a script tag

HTML
<script async src="https://cdn.playstep.app/referrals/v1/referrals.js"
        data-app-key="ps_pub_prod_your_key"
        data-app-domains="app.acme.io"
        data-consent="required"></script>

It attaches to window.playstep once PlayStep's loader has put it there, and works on its own on pages without it. window.playstepReferrals is the add-on (consent, myLink). Pin a version with its integrity from https://cdn.playstep.app/referrals/<version>/manifest.json.

Referral and affiliate tracking for commissions needs consent in the EU (France's CNIL says so for affiliate billing trackers). With consent: 'required' (or data-consent="required"), the add-on keeps the visit in memory only and stores nothing until the visitor agrees:

TypeScript
cookieBanner.onAccept(() => ref.consent(true))
cookieBanner.onReject(() => ref.consent(false)) // forgets the visit

A promo code the user types in needs no cookie: ask for it at signup and send it from your server (Server API).

Read what it remembered

ref.touches is where this visitor came from: the first touch it saw and the latest. Pass them to your own signup form or analytics if you like:

TypeScript
const { first, last } = ref.touches
signupForm.hidden.source = first?.utm?.source ?? first?.referrer ?? 'direct'

When the app has a friend referral program, each signed-in user has their own link and code:

TypeScript
const mine = await ref.myLink()
// { link: 'https://go.playstep.app/f-3k9x2m7q1a', code: 'K3X9M2Q1' }, or null without a friend program

ref.myLink() answers null before identify and when the app has no friend program. The answer is the same every time, and the browser keeps it for a day.

What it sends

WhenWhereWhat
A page view with a ref, UTM tags or another site as referrerNowhere: a first-party cookie, _ps_refThe click id, ref, UTM tags and the referring host (never the full referring URL), with the time
identifyPOST /v1/referrals/attributionYour publishable key, the user's hashed key, the first and last touch, and the hashed email if you passed one
myLink()GET /v1/referrals/meYour publishable key and the user's hashed key

Each user's touches are sent once. A click id only counts once, for one user, inside the program's attribution window, and only for the app its link belongs to.

Search the docs and guides.

Request a demo

We set up every new PlayStep workspace with its team. Leave your name and email and we'll book a demo and get you started.

We use your email only to arrange the demo. See the privacy policy.