This guide sends customer survey results from Survicate to Datadog every hour. A scheduled GitHub Actions job fetches the responses of the previous hour, counts them per survey and sends the counts to Datadog as structured logs. Datadog then computes the CSAT percentage, the share of detractors and the average rating, which you can put next to RUM and error data on one dashboard. The script runs on Node.js 24 with the built-in fetch and has no npm dependencies. It uses the Survicate Data Export API v2 and the Datadog Logs and Metrics APIs v2, all checked on 1 December 2026.
CSAT in this guide follows the common definition: the share of ratings of 4 or 5 on a scale from 1 to 5, where a rating of 1 or 2 counts as a detractor.
The data flow
- An hourly GitHub Actions job fetches the responses of the previous hour.
- For each survey, the job counts the responses, the ratings from 1 to 5 and the choices per question.
- It sends the counts to the Datadog Logs HTTP intake as structured logs.
- Log-based metrics turn the counts into metrics, and dashboard formulas compute CSAT, detractor share and average rating from them.
- The job sends metrics about its own runs, and a monitor alerts when a run fails or does not happen.
Send counts, not percentages, because you can add up counts across hours, locales and channels but you cannot add up percentages. Datadog computes the percentage at query time, over the period and the filter you choose.
The job also never sends single responses, because a summary per survey and hour holds no answer from one person and keeps the number of logs low.
Fetch the previous hour from Survicate
The Data Export API lives at https://data-api.survicate.com/v2. Create an API key under Settings, Organization, Access Keys (only owners and admins can do that), and send the key in the header Authorization: Basic <key>.
The endpoint GET /surveys/{survey_id}/responses returns the responses of one survey. Some details from the docs:
startis the newer bound andendthe older one, both inclusive and in ISO 8601 with microseconds.items_per_pagegoes up to 100. The response haspagination_data.has_moreandnext_url, a path relative to the base URL that you follow untilhas_moreisfalse.- Custom attributes only come back when you name them with
attributes[], and without that parameter both attribute lists are empty. The names are case-sensitive. - The API allows 5 concurrent requests and 1,000 requests per minute per workspace and answers
429above that, so the script below sends one request at a time.
A small config file lists the surveys, where ratings maps the ID of each 1 to 5 rating question to a readable name.
[
{
"id": "a1b2c3d4e5f6a7b8",
"name": "post_purchase",
"channel": "web",
"ratings": { "1001": "shopping_experience", "1003": "delivery" }
}
]
All snippets below go in one file, sync.mts.
import { readFile } from 'node:fs/promises';
type Survey = { id: string; name: string; channel: string; ratings: Record<string, string> };
type Attribute = { name: string; value: string };
type Choice = { content?: string };
type Answer = {
question_id: number;
question_type: string;
answer?: Choice & { rating?: number };
answers?: Choice[];
};
type SurveyResponse = {
device_type?: string;
answers: Answer[];
attributes: Attribute[];
respondent: { attributes: Attribute[] };
};
type Page = { data: SurveyResponse[]; pagination_data: { has_more: boolean; next_url?: string } };
type Entry = Record<string, string | number>;
const SURVICATE = 'https://data-api.survicate.com/v2';
const { SURVICATE_API_KEY, DD_API_KEY, DD_SITE = 'datadoghq.eu', SYNC_HOUR } = process.env;
const ALLOWED_ATTRIBUTES = ['locale', 'country', 'logged_in'];
const CHOICE_TYPES = new Set(['single', 'multiple', 'dropdown_list']);
function hourWindow(override?: string) {
const from = override ? new Date(`${override}:00:00Z`) : new Date(Date.now() - 3_600_000);
const hour = from.toISOString().slice(0, 13); // e.g. 2026-12-01T10
return { hour, start: `${hour}:59:59.999999Z`, end: `${hour}:00:00.000000Z` };
}
async function fetchResponses(surveyId: string, start: string, end: string) {
const query = [
`start=${start}`,
`end=${end}`,
'items_per_page=100',
...ALLOWED_ATTRIBUTES.map((name) => `attributes[]=${encodeURIComponent(name)}`),
].join('&');
let path: string | undefined = `/surveys/${surveyId}/responses?${query}`;
const responses: SurveyResponse[] = [];
while (path) {
const res: Response = await fetch(SURVICATE + path, {
headers: { Authorization: `Basic ${SURVICATE_API_KEY}` },
});
if (!res.ok) throw new Error(`Survicate answered ${res.status}`);
const body: Page = await res.json();
responses.push(...body.data);
path = body.pagination_data.has_more ? body.pagination_data.next_url : undefined;
}
return responses;
}
hourWindow takes the full UTC hour before the current time, so a run at 10:07 fetches 09:00:00 to 09:59:59.999999. SYNC_HOUR lets you fetch a specific hour again, for example after a failed run.
Keep personal data out
Survey data can contain personal data: a respondent can type an email address into a comment, and a custom attribute can hold an order ID. Decide what may leave the job and drop the rest, rather than trying to filter out the bad parts afterwards.
The script uses an allowlist in two places. It asks Survicate only for the attributes in ALLOWED_ATTRIBUTES, and then dimensions keeps only those names again in case the response holds more.
function dimensions(response: SurveyResponse): Entry {
const dims: Entry = { device_type: (response.device_type ?? 'unknown').toLowerCase() };
for (const { name, value } of [...response.respondent.attributes, ...response.attributes]) {
if (ALLOWED_ATTRIBUTES.includes(name)) dims[name] = String(value).toLowerCase();
}
return dims;
}
What the job never reads:
commentandinsighton an answer, andfieldsfrom contact forms, because these hold free text.- The page
url, because a query string can hold an order ID or an email address. - The respondent
uuid. - Any attribute that is not on the allowlist, such as an email address or an order ID.
Keep the allowed values low in cardinality as well: a country or a locale is fine, but a postcode is not.
Count per survey and hour
summarise turns the responses of one hour into a few log entries, each with the same dimensions plus a kind:
responses: the number of responses.rating: per rating question, the number of ratings (rated), the count per score (r1tor5),satisfied(4 or 5),detractors(1 or 2) andrating_sum.choice: per choice question, the number of picks per option, with the option label turned into a slug such asfast_delivery.
const slug = (text: string) => text.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '');
function summarise(survey: Survey, responses: SurveyResponse[], hour: string): Entry[] {
const entries = new Map<string, Entry>();
const add = (fields: Entry, counts: Record<string, number>) => {
const key = JSON.stringify(fields);
const entry = entries.get(key) ?? { ...fields };
for (const [name, value] of Object.entries(counts)) {
entry[name] = Number(entry[name] ?? 0) + value;
}
entries.set(key, entry);
};
for (const response of responses) {
const base = { survey: survey.name, channel: survey.channel, hour, ...dimensions(response) };
add({ ...base, kind: 'responses' }, { responses: 1 });
for (const answer of response.answers) {
const question = survey.ratings[answer.question_id];
const rating = answer.answer?.rating;
if (question && rating && rating >= 1 && rating <= 5) {
add({ ...base, kind: 'rating', question }, {
rated: 1,
[`r${rating}`]: 1,
satisfied: rating >= 4 ? 1 : 0,
detractors: rating <= 2 ? 1 : 0,
rating_sum: rating,
});
} else if (CHOICE_TYPES.has(answer.question_type)) {
for (const picked of answer.answers ?? [answer.answer ?? {}]) {
if (!picked.content) continue;
add(
{ ...base, kind: 'choice', question: `q${answer.question_id}`, choice: slug(picked.content) },
{ picks: 1 },
);
}
}
}
}
return [...entries.values()];
}
The option label is the text of the choice, not something the respondent typed. If a survey runs in several languages, the labels differ per language, so in that case key the choice on the answer id instead.
Send structured logs to Datadog
The Logs HTTP intake takes a JSON array of log objects. Each object needs a message, and extra fields become log attributes, such as @survey and @rated. The endpoint for the EU site is https://http-intake.logs.datadoghq.eu/api/v2/logs.
async function sendLogs(entries: Entry[]) {
for (let i = 0; i < entries.length; i += 1000) {
const batch = entries.slice(i, i + 1000).map((entry) => ({
ddsource: 'survicate',
service: 'survey-sync',
ddtags: 'env:production',
message: `survey ${entry.kind} ${entry.survey}`,
...entry,
}));
const res = await fetch(`https://http-intake.logs.${DD_SITE}/api/v2/logs`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'DD-API-KEY': DD_API_KEY ?? '' },
body: JSON.stringify(batch),
});
if (res.status !== 202) throw new Error(`Datadog logs answered ${res.status}`);
}
}
The docs allow up to 1,000 entries per array, 5 MB per payload before compression and 1 MB per log, and a successful call returns 202. Datadog recommends gzip compression with the header Content-Encoding: gzip, and you should retry the request on 408, 429, 500 or 503.
The logs carry no timestamp of their own, so Datadog uses the time of arrival. That is on purpose: log-based metrics only count logs with a timestamp in the past 20 minutes, so if you backdate the logs to the survey hour, the metrics miss them. The hour attribute keeps the source hour for log searches.
Compute CSAT, detractors and average rating
Create log-based metrics under Logs, Generate Metrics, using the query source:survicate @kind:rating and measuring one attribute per metric:
| Metric | Measure |
|---|---|
survey.rated |
@rated |
survey.satisfied |
@satisfied |
survey.detractors |
@detractors |
survey.rating_sum |
@rating_sum |
Add a fifth metric, survey.responses, with the query source:survicate @kind:responses and the measure @responses. Group by @survey, @question, @channel, @locale and @device_type, and the metric tags get the same names without the @.
A metric on a numeric attribute is a distribution, so you can query its sum. In a dashboard widget, add the queries and a formula:
a = sum:survey.satisfied{survey:post_purchase,question:shopping_experience}
b = sum:survey.rated{survey:post_purchase,question:shopping_experience}
c = sum:survey.detractors{survey:post_purchase,question:shopping_experience}
d = sum:survey.rating_sum{survey:post_purchase,question:shopping_experience}
CSAT % = 100 * a / b
Detractors % = 100 * c / b
Average = d / b
Log-based metrics keep the counts for 15 months, even when you keep the logs themselves for a shorter time. They count as custom metrics, and each unique combination of tag values is one custom metric, so keep the group-by list short. Leave the choice counts in the logs and query them there.
Hourly counts are small, so one unhappy customer moves an hourly CSAT a lot. Look at CSAT per day or per week instead, for example in a query value widget over the last 7 days.
Watch the job itself
A sync that stops looks the same as a quiet hour, so at the end of each run the job sends three gauges through the metrics API: success, duration and the number of responses.
async function sendRunMetrics(success: boolean, durationMs: number, responses: number) {
const timestamp = Math.floor(Date.now() / 1000);
const tags = ['service:survey-sync', 'env:production'];
const gauge = (metric: string, value: number) => ({
metric,
type: 3,
points: [{ timestamp, value }],
tags,
});
await fetch(`https://api.${DD_SITE}/api/v2/series`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'DD-API-KEY': DD_API_KEY ?? '' },
body: JSON.stringify({
series: [
gauge('survey_sync.run.success', success ? 1 : 0),
gauge('survey_sync.run.duration_ms', durationMs),
gauge('survey_sync.responses', responses),
],
}),
});
}
const started = Date.now();
const { hour, start, end } = hourWindow(SYNC_HOUR || undefined);
const surveys: Survey[] = JSON.parse(await readFile('surveys.json', 'utf8'));
let total = 0;
try {
for (const survey of surveys) {
const responses = await fetchResponses(survey.id, start, end);
total += responses.length;
await sendLogs(summarise(survey, responses, hour));
}
await sendRunMetrics(true, Date.now() - started, total);
} catch (error) {
await sendRunMetrics(false, Date.now() - started, total);
throw error;
}
Create a metric monitor that alerts when no run succeeded in the last two hours:
max(last_2h):max:survey_sync.run.success{service:survey-sync} < 1
Turn on the no data notification in the same monitor, so that it also alerts when the job stops sending metrics at all.
Run it every hour in GitHub Actions
name: Survey sync
on:
schedule:
- cron: '7 * * * *'
workflow_dispatch:
inputs:
hour:
description: 'UTC hour to sync again, for example 2026-12-01T10'
required: false
concurrency:
group: survey-sync
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: node sync.mts
env:
SURVICATE_API_KEY: ${{ secrets.SURVICATE_API_KEY }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_SITE: datadoghq.eu
SYNC_HOUR: ${{ inputs.hour }}
Scheduled runs can start late when GitHub is busy, mostly at the start of each hour, so the cron runs at seven minutes past the hour to stay out of that peak. A delay of a few minutes does not matter, because the script always fetches the previous full hour. To fetch a missed hour again, start the workflow by hand and fill in the hour. In a public repository, GitHub turns off scheduled workflows after 60 days without activity.
Put CSAT next to RUM and errors
The point of the sync is one dashboard that shows what customers say next to what the site does, so put these widgets side by side with the same time range:
- CSAT % and detractor share per day, from the formulas above.
- The count of RUM errors on the checkout views.
- The 75th percentile of
@view.largest_contentful_paintfor the checkout views. - Your backend error rate from APM, if you have it.
When an incident happens, you can then check whether customers noticed it. If you still need RUM, the guide on Datadog RUM and APM for the Next.js App Router covers the setup.
In practice
An international cosmetics retailer asks customers for feedback with surveys on the website, in the app and by email. After a purchase, the surveys ask about the shopping experience, the brand and delivery issues. The answers were in the survey tool while performance and error data were in Datadog, so the teams could not see both in one place.
Working in the client’s architecture team, we proposed the sync in May 2026 and built it in July 2026, and a DevOps engineer helped with the setup. Every hour, a GitHub Actions job fetches the answers of the previous hour from the Survicate Data Export API. It then counts the number of responses, the ratings from 1 to 5 and the choices per question for each survey. The data goes to Datadog as structured logs, and Datadog calculates the CSAT percentage, the share of detractors and the average rating. The job also sends metrics about its own runs.
An allowlist decides which attributes are sent, so fields such as the email address and the order ID are dropped, while free text answers are never sent at all. In September 2026, after a checkout incident, the team checked the CSAT data and saw that CSAT had not dropped. In November 2026, delivery satisfaction and daily totals were added, and the CSAT data can now be compared with RUM data. Read the case study on survey CSAT metrics in Datadog.
Checklist
- Fetch full hours, with
startas the newer bound andendas the older one. - Follow
next_urluntilhas_moreisfalse. - Request only the attributes on your allowlist, and filter again in code.
- Never read comments, insights, form fields or page URLs.
- Send counts, not percentages.
- Let Datadog set the log timestamp, so log-based metrics count the logs.
- Keep the group-by list of log-based metrics short.
- Compute CSAT as the share of 4 and 5 ratings, per day or per week.
- Send run metrics and alert on failed or missing runs.
- Put CSAT, RUM errors and LCP on one dashboard.
For a review of how survey, RUM and error data fit together in your Datadog setup, see the frontend observability assessment or get in touch.
Sources
- Survicate: Data Export API setup
- Survicate: Data Export API responses
- Datadog: Logs API
- Datadog: Generate metrics from ingested logs
- Datadog: Submit metrics API
- Datadog: Custom metrics
- Datadog: Metric monitor
- Datadog: Configure monitors
- Datadog: RUM browser data collected
- GitHub Docs: Events that trigger workflows