Skip to content

Events

The SDK records what happens in your app as events, queues them on the phone, and sends them in batches every 30 seconds, as soon as 50 are waiting, and when the app goes to the background. Your team uses them in segments, message triggers, workflows and goals. There is nothing to draw.

Without any code of yours beyond the calls on these pages, the SDK records:

EventWhenProps
app_openedThe app starts, or comes back to the front.
session_endedThe app goes to the background.seconds
app_updatedThe first start of a new appVersion.from, to
screen_viewedYou call crm.screen(name).screen
push_permission_changed, location_permission_changedYou tell it the answer changed (permissionChanged).allowed
push_openedA push is tapped (handlePushTap), any push.type, notice
link_openedA link of PurrCRM‘s is followed.link, from, saved

What users do with in-app messages and the messenger is sent as receipts and messages, not as events. These are standard events, on Settings › your app › Data › Events.

Name each of your screens as it shows:

crm.screen("wallet") // records screen_viewed {screen: wallet}

Use a name, the same every time; never a path or an id. The same name twice in a row is recorded once. It also lets through an in-app message held for that screen.

  1. Declare them in CrmConfig.customEvents:

    CrmConfig(
    apiBase: URL(string: "https://app.purrcrm.com")!,
    appKey: appKey,
    appVersion: appVersion,
    customEvents: ["order_placed", "table_booked"])
  2. Record them:

    crm.track("order_placed", ["total": "1250", "items": "3"])

Names are lower case with underscores. Props are strings, at most 10, each at most 120 characters; blank ones are left out. PurrCRM reads a number, a date or money from its string by the event’s definition. Money is a whole number of the smallest unit, such as pence: 1250 for £12.50.

The SDK drops a name you did not declare in customEvents (and logs it when debug is on), so check the log at your desk. On PurrCRM, a new event is accepted the first time and marked for review, unless your app has Strict data on, when it must be defined on Settings › your app › Data first. See Data.

Tell the SDK when you learn the user’s answer to a permission:

await crm.permissionChanged("push", allowed: true)
await crm.permissionChanged("location", allowed: false)

nil means not asked yet. Only a change from an answer it already knew is recorded, so call it as often as you like.

  • Events are kept for the user signed in. Before a session is known, at most 50 are held; then they are kept for the user, or dropped when nobody is signed in.
  • The queue survives a relaunch (in UserDefaults), holds at most 500, and drops events older than 7 days.
  • A failed batch waits 30 seconds, doubling up to 30 minutes, or as long as PurrCRM says. A batch PurrCRM refuses for good is dropped, so it holds nothing up.
  • await crm.flushEvents() sends what is queued now.

The setup check’s Queue row shows how many are waiting and how the last batch went; its Send a test event button records one and sends it at once.

If a user turns product analytics off in your settings, start their session with CrmSession(guestId: id, productEventsOff: true): nothing is recorded or sent for them. Nothing is recorded for nobody either.

Events your servers see, such as a payment, are better sent from the backend, with the server API.