Help centre
العربية Back to sayvara.com

In-app surveys

Show a short survey inside your web or mobile app after something happens, tied to the signed-in user, with targeting, sampling and limits.

Updated

Add-on, available on request.

The in-app SDK shows a short survey inside your app after something happens, such as a delivered order or a closed ticket. Your app reports events, the SDK checks your rules, and the survey opens for the signed-in user. Answers land in Responses like answers from any other channel.

Only owners and admins can open the In-app SDK page.

Platform status

Platform Status
Web apps (JavaScript) Comes with the add-on. It is not published on npm.
React Native The same package as the web SDK, with a React Native presenter. Not published on npm.
iOS (Swift, iOS 14 and newer) Source code only: not built, tested or published.
Android (Kotlin, Android 6 and newer) Source code only: not built, tested or published.

The In-app SDK page says the same. You can add apps and set them up there now.

How it works

  1. You add an app on the In-app SDK page. You get a public app key and a secret identity secret.
  2. The app key goes inside your app. The identity secret stays on your server.
  3. Your server signs a short user token for the signed-in user with the identity secret.
  4. Your app gives the token to the SDK and reports events. When your rules say so, the SDK asks the user.
  5. Sayvara checks the token and the limits, then gives a survey link that works for 30 minutes.

The user token stops one user from answering as another.

Add an app

  1. Go to In-app SDK in the side menu and select Add app.
  2. Fill in:
    • Name: for your team only, for example "Customer app".
    • Survey: the survey the app shows.
    • Language when the app does not say: Arabic or English.
    • Who can answer: Signed-in users only (safest: no survey link without a user token from your server) or Anyone; signed-in users are checked.
    • Web origins: web apps only. One https address per line, for example https://app.example.com. Leave it empty for mobile apps.
    • Events that may ask: for example order_delivered. Empty means the app asks only when it calls show().
    • Survey links per day: from 1 to 100,000 (5,000 at first).
  3. Select Add app.
  4. Copy the identity secret now. You see it only once. Keep it in your server's secret store, never in an app or a web page. Then select I have copied it.

The app key starts with ak_. It is public. The identity secret starts with sis_.

Sign the user token on your server

The user token is a JWT signed with HS256. Use the whole identity secret, sis_ included, as the key. Claims:

Claim Value
sub Your user id: 1 to 128 letters, digits and _ . : @ + -, no spaces. Not an email address or a phone number.
iat When you signed it.
exp When it ends: at most 30 days after iat.
nbf Optional: not before this time.
aud Optional: the app key, or a list that includes it.

Sayvara refuses tokens with any other algorithm. The examples on the In-app SDK page show server code and web app code with your app key.

Report events in your app

sayvara.identify(userToken);             // after sign-in; sayvara.reset() at sign-out
sayvara.setScreen('Receipt');            // optional, no personal data
await sayvara.track('order_delivered');  // asks when the rules say so
await sayvara.show();                    // or ask now, within the rules
  • track(event) counts the event and asks when the rules allow.
  • show() asks now. It still follows the rules. show({ force: true }) skips the rules on the device, for an "ask me" button in your app; see Checks on the server.
  • Neither call ever throws an error into your app. They return what happened, for example opened, dismissed, not_sampled, capped or not_targeted.

On the web, the SDK first shows a small card; the survey opens in a new tab. In React Native, the survey opens in a web view inside the app.

Rules

The In-app SDK page sets the events. The other rules start with the defaults below.

Rule Default What it does
Events none Events that may ask, up to 20.
Event count 1 The event must happen this many times (1 to 100) before the first ask.
Delay 2 seconds Wait between the event and the ask (0 to 30), so the app can finish its own screen.
Share of users 100 % From 1 to 100. Each user is picked once.
Asks at most 2 in 30 days 1 to 20 asks in 1 to 365 days.
Quiet after the survey is opened 90 days 0 to 730.
Quiet after "Not now" 14 days 0 to 365.
Screens any Up to 20 screen names, as your app passes them to setScreen.
Platforms any ios, android, web or react-native.
Lowest app version any For example 2.4. Compared number by number.
Locales any Up to 10, for example ar or en-GB. ar covers ar-SA and ar-EG.
Attributes none Up to 10 equality tests, for example plan equals gold.

About targeting (screens, platforms, app version, locales and attributes):

  • The web and React Native SDK checks them on the device. The iOS and Android source does not check them.
  • Attributes are facts your app sets with setAttributes, for example { plan: 'gold' }. They stay on the device and are never sent to Sayvara. Do not put personal data in them.
  • The rules themselves are public: any app with the app key can read them. So Sayvara refuses attribute names that usually carry personal data or secrets (such as email, phone, id, user, name or token), and values that look like personal data (an @, six or more digits in a row, or a phone number). Dates such as 2024-11-12 and version numbers such as 1.10.100.1000 are fine.
  • With a lowest app version, tell the SDK the app's version. Without it, that rule never asks.

Change the other rules

The In-app SDK page changes the events only. When it saves, the app keeps its other rules. To change the event count, delay, share of users, asks and quiet days, screens, platforms, lowest app version, locales or attributes, send the app's rules to the Sayvara API:

PATCH /v1/tenants/{tenantId}/sdk-apps/{appId}
Content-Type: application/json

{ "rules": { "events": ["order_delivered"], "samplePercent": 25, "platforms": ["ios", "android"],
  "minAppVersion": "2.4", "locales": ["ar"], "attributes": [{ "key": "plan", "equals": "gold" }],
  "frequency": { "maxShows": 1, "windowDays": 60 } } }
  • This is the call the In-app SDK page makes. It works while you are signed in to Sayvara as an owner or admin; API keys and API clients cannot call it, so it is not in the API reference.
  • rules replaces all the rules at once. A rule you leave out goes back to its default in the table above, the events included. First read the app with GET /v1/tenants/{tenantId}/sdk-apps, change what you need and send every rule back.
  • The names are events, minEventCount, delaySeconds, samplePercent, frequency (maxShows, windowDays, afterAnswerDays, afterDismissDays), screens, platforms, minAppVersion, locales and attributes (key and equals), with the limits in the table above.

You can also email support (see Getting help) with the app's name and the rules you want.

Checks on the server

For every signed-in user with a valid user token, Sayvara checks these again before it gives a survey link, whichever SDK the app uses. For these users, Sayvara decides this itself:

  • Share of users: the same user gets the same answer on every device.
  • Asks at most: counted per user, across devices.
  • show({ force: true }) gets one extra link per user in each period of Asks at most. After that, Sayvara refuses until the period ends.

The quiet days after the survey is opened or after "Not now" are checked on the device only.

More limits on survey links:

Limit Value
Per signed-in user 10 links a day
Users without a token (only with Anyone; signed-in users are checked) 30 links an hour from one network address, and at most 20 % of the app's daily limit
Per app Survey links per day, counted per Riyadh day

Users without a token are counted on their own device only, so clearing the app's data starts their limits again. With Anyone; signed-in users are checked, a changed copy of your app can also leave the token out and be treated as a user without a token: it then gets only the device rules and the limits for users without a token above. For strict limits on every survey link, choose Signed-in users only.

New identity secret

If the secret may have leaked, or as routine:

  1. Open the app's actions and select New identity secret.
  2. Select Make new secret and copy the new secret.
  3. Put it on your server.

The previous secret keeps working for 24 hours, so your server can switch without a gap.

Pause or remove

  • Pause stops new survey links within a minute. Resume starts them again.
  • Remove stops the app for good. This cannot be undone.

Survey links already given out keep working for up to 30 minutes.

Privacy

  • On the device, the SDK keeps a sampling roll, event counts and when it asked, per app and per user. It names the user by a hash, not by the id.
  • Each survey link carries the verified user id from your system, the event and the screen name. They are kept with the answer.