How a Unity developer adds the end of experience rating to an experience that runs on the
Hydra fleet. The package is in this repository under
unity/com.experiencenet.hydranps.
The card the package draws is the card in docs/design/rating-card.md. That file is the
single source for every platform. The Unity package builds the card in code from the
values in that spec, so it cannot drift from the card on the screens, the tablets and the
headsets.
An experience developer who wants to know how visitors felt, and who does not want to build a rating screen, host a server or hold a credential.
The whole job is one prefab in front of the ending screen.
Start at https://hydranps.experiencenet.com/unity. That page carries these steps, the card itself, and a download button that always points at the newest published package.
This repository is private, so Package Manager cannot read it over a git URL unless the developer has access to it. Every release publishes the package as a UPM tarball on the release server, which serves a plain public download:
https://hydranps.experiencenet.com/unity/package.tgz
That link redirects to the file on the release server, which is
https://releases.experiencenet.com/hydranps/production/<service version>/com.experiencenet.hydranps-<package version>.tgz.
The current service version is at
https://releases.experiencenet.com/api/v1/releases/hydranps/production. In Unity:
Window > Package Manager > + > Add package from tarball.
With access to the repository, + > Add package from git URL and
https://github.com/cederikdotcom/hydranps.git?path=/unity/com.experiencenet.hydranps
works too, and copying the folder into the project Packages folder always works.
Unity 2021.3 or later. The only dependency is com.unity.ugui.
No code. Drag Runtime/Prefabs/HydraNPSCard into the scene, disable the object, wire
On Finished to whatever shows the ending screen, and enable the object where the
experience used to show that screen.
One line.
using ExperienceNet.HydraNPS;
HydraNPS.Ask(ShowEndingScreen);
On Rated and the Action<int> overload give the stars, 1 to 5, or 0 when nobody
answered. Almost no experience needs that number: the server keeps it.
Call HydraNPS.StartSession() when the visit starts if you want the reported duration to
cover the visit. Without it the duration starts at the card.
| Field | Default | What it does |
|---|---|---|
| Experience Name | empty | The catalog name, for example rizeof. Empty means the Unity product name folded to a slug. A configuration file on the machine wins over this field, and the body wins over both. |
| Show On Enable | on | Open the card when the object is enabled. This is what makes the no code pattern work. |
| Auto Dismiss Seconds | 10 | Seconds with no input before the card closes itself. The spec says 10. Changing it breaks the comparison with the other platforms. |
| Render Mode | Screen Space Overlay | Correct for every streamed experience. |
| World Space Distance | 2 | Metres in front of the camera, in world space mode only. |
Use world space mode only for an experience the visitor sees in a headset. A screen space overlay does not appear in a headset. The world space path is written and is not yet measured on a device.
On Finished fires when the card closes, not when the server answers.Time.timeScale = 0 is fine.The experience posts to hydrabody on the loopback interface of the body it runs on:
POST http://127.0.0.1:47991/api/v1/nps/rating
Content-Type: application/json
{
"source": "experience",
"experience": "rizeof",
"score": 8,
"score_scale": "5-star",
"experience_version": "1.4.2",
"session_hint": "exp-3f91ab02-1761590400123"
}
The body fills in session_id, head_id, body_id, district, venue and
duration_ms from the experience session it is already running, and forwards the record to
hydranps with the write only submit_token it holds. Nothing secret is in the build and
nothing needs configuring per venue.
Reaching the loopback interface already proves the caller runs on the body, so the relay
takes no credential. The score is 1 to 10 on the wire, stars * 2, which keeps head
records and browser records comparable.
This endpoint does not exist yet. hydrabody needs it, and hydracluster needs to
deliver nps_url and nps_token to bodies the way it already delivers
experience_library_url. Until that ships, use the direct transport.
For a developer machine, and for an experience that runs somewhere the Hydra fleet does not reach.
{
"transport": "direct",
"hydranps_url": "https://hydranps.experiencenet.com",
"submit_token": "<from the ExperienceNet team>",
"experience": "your-experience-name"
}
The experience then posts the full record to POST /api/v1/ratings with
Authorization: Bearer <submit_token>, and mints its own session_id
(exp-<device hash>-<start milliseconds>). A direct record cannot be joined to the head
record for the same visit, because the head mints its own id and never tells the body.
That limit is on issue #565 under "Session id".
The package reads its settings from disk, never from the build. First hit wins:
HydraNPS.Configure(), if the experience calls itHYDRANPS_CONFIG environment variablehydranps.json beside the executableC:\experiences\hydranps.json, or /etc/hydranps/experience.jsonHYDRANPS_TRANSPORT, HYDRANPS_URL, HYDRANPS_SUBMIT_TOKEN,
HYDRANPS_BODY_RELAY_URL and HYDRANPS_EXPERIENCE environment variablesA submit token in a build is a leaked token: a built experience is readable, and the developer ships it. That is why the token lives in a file on the machine that runs the experience, and why the fleet path uses the relay instead.
"transport": "disabled" shows the card and reports nothing. Use it for a demo build.
A post that fails on the network is appended to hydranps_queue.jsonl in
Application.persistentDataPath, with the queue time as a prefix. The file is flushed at
the next start of the experience, oldest first. A record older than 24 hours is dropped,
and the file holds 1000 records at most. A record flushed late carries
client_submitted_at, so the real moment survives.
A record the server refuses (400, 401, 403, 409) is not queued. A retry sends the same bytes and gets the same answer.
With the direct transport, against the live service:
# in the folder that holds the built experience
cat > hydranps.json <<'END'
{"transport":"direct","hydranps_url":"https://hydranps.experiencenet.com","submit_token":"<token>","experience":"nps-unity-test"}
END
Run the experience, reach the end, tap three stars, then read the record back:
curl -H "Authorization: Bearer <admin token>" \
"https://hydranps.experiencenet.com/api/v1/ratings?experience=nps-unity-test"
Expect score: 6 and score_scale: "5-star".
In the Unity editor the same file works if you put it one level above Assets, because
Application.dataPath points at Assets in the editor.
Until the service work on #579 lands, source, score_scale and experience_version
are accepted and dropped by the server, because POST /api/v1/ratings decodes into a
struct and ignores fields it does not know. The score, the experience and the session id
are stored.
These need an owner ruling before the experience side rating is on by default in a venue. They are tracked on the sub-issue for this work under #565.
<head_id>-<milliseconds> and the
experience cannot know it, so the two records never merge and the rated against total
ratio counts the visit twice. The fix is the same chain as above, or the session id
handover already flagged as out of scope on #565.end_reason for an experience record. The experience knows it reached its own
ending, which is not one of quit, timeout, error, shutdown or watchdog. The
package sends no end_reason and lets the body or the cluster label the session end.
The NPS average is computed over end_reason: quit only, so a record with no end
reason falls outside the headline metric until the body labels it.