Run an end-to-end test against production

Keep QA signups and test runs out of your numbers: flag test events with $internal, or erase the test users afterwards by distinct id.

Embed
Preview of the card
<a href="https://lucidace.com/help/test-against-production"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/e567d986-3c5f-4b96-b18b-63e613feaea9/social-card.svg?v=3e7ae33eec8b" alt="Run an end-to-end test against production" width="600" height="315"></a>

You can test a live integration without polluting the project's analytics. There are two tools, and they do different things: flag test events so reports leave them out, or erase the test users when you are done. Use the flag while testing and the erase to leave a clean project.

1. Flag test events with $internal

An event whose properties contain "$internal": true is marked as internal traffic when it is ingested. Queries, insights and dashboards leave internal events out by default; a query only counts them when it sets include_internal: true.

curl -s https://<capture-host>/v1/capture \
  -H 'content-type: application/json' \
  -d '{"api_key":"<project key>","event":"signup","distinct_id":"qa-user-1","properties":{"$internal":true,"plan":"pro"}}'

The browser SDK sets it for you after optOutInternal(). The boolean has to be true, not the string "true".

What this does not do:

  • The flag is applied at ingestion, so it does not hide events you sent earlier. For those, erase the users (below).

  • The live Events feed (GET /v1/projects/{project_id}/events) and POST /v1/projects/{project_id}/events/first-occurrence still return internal events: they list what was stored.

  • There is no $test property or test key. $internal is the one that exists.

Flag whole sets of test users instead

If you cannot change the events, add an internal-traffic rule. It flags matching events from then on:

curl -s -X POST https://<api-host>/v1/projects/<project_id>/internal-traffic/rules \
  -H 'authorization: Bearer <key with settings:write>' -H 'content-type: application/json' \
  -d '{"kind":"email_domain","value":"qa.example.com","note":"QA accounts"}'

Kinds are ip_cidr, email_domain and person_property (with key). List rules with GET .../internal-traffic/rules, remove one with DELETE .../internal-traffic/rules/{id}.

Separately, a retroactive traffic exclusion (POST .../traffic-exclusions, kind event_property with key and value) hides matching events at query time, including ones that arrived before the rule, and deleting it brings them back. It compares text, so it matches a property you send as a string such as "$test": "true"; see traffic exclusions.

When your test users share a distinct id pattern, exclude them by distinct id. * matches any run of characters, and without one the match is exact:

curl -s -X POST https://<api-host>/v1/projects/<project_id>/traffic-exclusions \
  -H 'authorization: Bearer <key with settings:write>' -H 'content-type: application/json' \
  -d '{"kind":"distinct_id","value":"qa_*"}'

The choice between the two:

  • Exclusion rule (reversible). Hides the matching events from every query, past and future. They are still stored, and deleting the rule brings them back.

  • persons/bulk_delete (permanent). Erases the people and their events (section 2). It takes exact distinct ids, not a pattern.

2. Erase the test users

DELETE /v1/projects/{project_id}/persons/{id} queues an erasure. It does remove the person's events: by default it deletes their events, sessions, experiment exposures, heatmap points and recordings, and forwards the delete to connected destinations that have a delete API. It is asynchronous: the call returns 202 with a deletion request, and a background job does the work, so check the request status before you declare the project clean.

Erase many test users by distinct id in one call (up to 1,000), which saves looking up person ids:

curl -s -X POST https://<api-host>/v1/projects/<project_id>/persons/bulk_delete \
  -H 'authorization: Bearer <key with privacy:execute or admin>' -H 'content-type: application/json' \
  -d '{"distinct_ids":["qa-user-1","qa-user-2"]}'

The response is 202. It lists the queued requests, the batch_id, and any errors (distinct ids that name no person are reported, not queued). Poll GET .../deletion-requests?batch_id=<batch_id> until each request has status done (the other values are pending, running, failed and cancelled); completed_at is when every store was verified erased. The body also takes events, recordings and keep_person (events and recordings default to true). Erasure is by person or distinct id only; there is no way to erase events by another property.

Needs a key with the privacy:execute scope or admin; the same key can poll deletion-requests. This is permanent: only list ids you created for the test.

Tidy up experiments

If the test ran an experiment, POST .../experiments/{id}/reset puts it back to draft, clears its results and turns its flag off, so the real run starts fresh.

A clean test run

  1. Send every test event with "$internal": true.

  2. Do the end-to-end run. Reports stay clean as you go.

  3. Run persons/bulk_delete with the test distinct ids, then check the deletion requests finish.

  4. Reset any experiment you started.

Updated