Issue trackers
One GitHub or GitLab issue per feedback, opened, closed and reopened along with it through the server's lifecycle hooks.
@siteping/integration-issues builds the lifecycle hooks of @siteping/server so that every feedback gets its own issue on GitHub or GitLab:
- created → an issue opens, labelled
siteping, with the message, the page, a deep link, the annotated elements, the reviewer's environment and diagnostics; - resolved or won't fix → the issue closes; reopened → it reopens;
- deleted → the issue closes with a comment. If the tracker is unreachable, the delete is refused and can be retried.
No database column is added: the first line of each issue is a hidden marker naming its feedback.
npm i @siteping/integration-issuesIt runs wherever the server runs (Fetch API only). It depends on no server version: its hooks match the server's types structurally, so it installs next to @siteping/server or @siteping/adapter-prisma, which passes hooks through like every other server option.
GitHub
// app/api/siteping/route.ts
import { createSitepingHandler } from "@siteping/server";
import { createIssueTrackerHooks } from "@siteping/integration-issues";
import { createGitHubTracker } from "@siteping/integration-issues/github";
import { store } from "@/lib/siteping-store";
export const { GET, POST, PATCH, DELETE, OPTIONS } = createSitepingHandler({
store,
apiKey: process.env.SITEPING_API_KEY,
hooks: createIssueTrackerHooks({
tracker: createGitHubTracker({ repository: "acme/site", token: process.env.GITHUB_TOKEN! }),
siteUrl: "https://acme.com",
}),
});The token is a fine-grained personal access token limited to that repository, with the Issues permission set to Read and write. Its account also needs write access to the repository: GitHub silently drops the labels of a new issue created by anyone else, and without its siteping label SitePing cannot find the issue again. When that happens the handler logs an error that names the missing permission.
On GitHub Enterprise Server, pass apiBaseUrl: "https://github.acme.com/api/v3".
GitLab
import { createGitLabTracker } from "@siteping/integration-issues/gitlab";
createIssueTrackerHooks({
tracker: createGitLabTracker({ project: "acme/site", token: process.env.GITLAB_TOKEN! }),
siteUrl: "https://acme.com",
});project is the numeric id or the full path (group/subgroup/project). The token is a personal, project or group access token with the api scope, for a member with at least the Reporter role: GitLab ignores labels set by Guest members, and the handler then logs an error, as on GitHub.
On a self-managed instance, pass apiBaseUrl: "https://gitlab.acme.com/api/v4".
Status mapping
| Feedback | GitHub issue | GitLab issue |
|---|---|---|
open, in_progress | Reopened | Reopened |
resolved | Closed as completed | Closed |
wont_fix | Closed as not planned | Closed |
| Deleted | Closed as not planned if still open, with a comment. An issue already closed keeps its reason | Closed, with a comment |
Moving between open and in_progress only looks the issue up, and writes nothing to an issue that is open. With syncStatus: false, issues are only created and closed on delete.
The sync runs one way, from SitePing to the tracker: closing the issue on GitHub does not resolve the feedback.
What an issue contains
The title is [SitePing] followed by the message on one line, truncated to 255 characters. The body has these sections:
- Message
- Type
- Page, resolved against
siteUrl, without the credentials a URL may carry - Open in the page: a link that opens the page with the feedback focused, once the widget's
deepLinkoption is on. It is only added for a page onsiteUrl's origin - Annotations: element, CSS selector and text of up to 10 annotations
- Author, Viewport, User agent
- Screenshot, when it has an
httpsURL - Console diagnostics and Network diagnostics: the first 5 entries of each, when the widget captured them
Annotation fields are cut at 300 characters and diagnostic entries at 500. If the body would still pass 60,000 characters, close to GitHub's limit of 65,536, which only a crafted feedback reaches, the annotations and diagnostics are left out and a note says so.
Some things are left out:
- The reviewer's email, unless you set
includeAuthorEmail: true. - Screenshots stored inline as
data:URLs, which is what happens without a screenshot storage. Trackers do not render them. - Discussion threads.
Everything in the body comes from anonymous visitors, so it is quoted as code. The deep link is the only live link, and it only ever points to siteUrl: a visitor who sends another site's URL gets a quoted page and no link. A message can contain @octocat, #12, <!--, a Markdown link or an image, and none of it notifies anyone, links to another issue, hides text or loads anything. In the title, a zero-width space follows each reference sigil (@, # and GH-, plus GitLab's !, &, ~, % and $) and splits each ://, since GitLab also turns a URL pointing at an issue or merge request into a reference. A bare commit SHA is left as typed: GitLab still links it when it names one of the project's own commits.
Public repositories. An issue in a public repository is public: every feedback's message, page, reviewer name, user agent, diagnostics and screenshot become readable by anyone. The screenshot is embedded from its storage URL, which
redactdoes not touch. Prefer a private repository, and useredactfor secrets that end up in URLs or console messages. To leave screenshots out, extend the default issue withformatIssue({ ...feedback, screenshotUrl: null }, options).
Options
createIssueTrackerHooks takes:
| Option | Type | Default | What it does |
|---|---|---|---|
tracker | IssueTracker | — | Required. createGitHubTracker, createGitLabTracker or your own |
siteUrl | string | — | Origin of the site under review. The widget records location.pathname as the page URL by default, which resolves against it. The deep link only points to this origin: without siteUrl, issues have no deep link. It must be an absolute http(s) URL such as https://acme.com: anything else throws when the hooks are built, so the route module fails to load |
deepLinkParam | string | false | "siteping" | Must match the widget's deepLink param. false leaves the link out |
labels | string[] | [] | Extra labels. siteping is always added |
redact | (text) => string | none | Applied by the built-in format to the message, author, page URL, user agent, annotation text and diagnostics before they leave your server. A custom formatIssue gets the feedback unredacted: call options.redact on what you copy, or extend the default issue. To redact before the feedback is even stored, use the server's beforeCreate |
includeAuthorEmail | boolean | false | Add the reviewer's email next to their name |
formatIssue | (feedback, options) => { title, body } | built-in | Your own title and Markdown, or the default extended. The marker is still added as the first line. Quoting visitor text is then up to you |
onIssueCreated | (feedback, issue) => void | — | Called with each issue opened (issue.key, issue.url), to send its link to a chat or keep it, say. The visitor's POST waits for it, and so do the feedback's later status changes and deletes and its project's next delete, so it must not wait for one of those itself. A throw is logged like a failed creation |
instance | string | — | Name of this deployment when several share one repository. See how issues are found again |
syncStatus | boolean | true | Close and reopen the issue when the status changes |
deletedCommentText | (feedbackId) => string | SitePing feedback `<id>` was deleted. | The comment left on the issue of a deleted feedback. A retried delete finds it by a hidden first line, so the text may change from one call to the next |
createGitHubTracker and createGitLabTracker also take apiBaseUrl, fetch (for a proxy or tests), timeoutMs (per request, default 5000) and maxListedPages (default 10, see how issues are found again).
Both check their options when they are called, and throw on a value that could not work: a repository that is not owner/name (a project that is neither an id nor a full path), an apiBaseUrl that is not an absolute http(s) URL or that carries credentials, a timeoutMs or maxListedPages that is not a positive integer (Number() of a misspelled variable is NaN), a timeoutMs over 2,147,483,647 (about 24 days, the longest delay a timer holds), or a token that is empty or has a space, a line break or an invisible character inside. The error never quotes the token, nor a refused repository, project or apiBaseUrl, which can carry one, as a clone URL does.
createIssueTrackerHooks returns plain onCreated, onUpdated and onDeleting hooks, and you can add onDeleted next to them. To run code of your own on one of those three, call the integration's hook from yours: a hook of the same name spread after them replaces theirs, and TypeScript does not flag it.
const issues = createIssueTrackerHooks({ tracker });
createSitepingHandler({
store,
hooks: {
...issues,
async onCreated(feedback) {
try {
await issues.onCreated(feedback);
} finally {
await searchIndex.add(feedback); // runs even when the tracker fails, whose error is still logged
}
},
onDeleted: (target) => audit.log("deleted", target),
},
});Extending the default issue
The built-in format is exported as formatIssue(feedback, options), and your formatIssue option receives those options: redact, deepLinkParam, includeAuthorEmail and siteUrl. Wrap it to add to the default issue instead of rewriting it, and the quoting of visitor text comes with it:
import { createIssueTrackerHooks, formatIssue } from "@siteping/integration-issues";
createIssueTrackerHooks({
tracker,
formatIssue: (feedback, options) => {
const issue = formatIssue(feedback, options);
return { ...issue, body: `${issue.body}\n\n## Release\n\n${process.env.RELEASE_NAME}` };
},
});Latency and failures
- Creating.
onCreatedis awaited before thePOSTanswers, so the widget waits for one tracker request, at mosttimeoutMs(5 seconds by default), then foronIssueCreated. If it fails (the tracker is down, or the token is wrong), the feedback is stored anyway and the error goes to the server'sloggeras[siteping] Hook onCreated failed, with the feedback's id. Nothing retries it: that feedback has no issue. When the label was dropped, the issue does exist and the same error names the missing permission, but SitePing cannot find that issue again, so status changes and deletes never reach it. Fix the permission, then label or close those issues by hand. - Changing a status. The
PATCHwaits for the issue's lookup, one search plus one listing request when the search misses (and up tomaxListedPagesmore when it fails), then for one write, each request at mosttimeoutMs. A tracker that does not answer the search withintimeoutMsis taken as down, and the lookup stops there. A search that fails at once (a refused connection, a rate limit) falls back to the listing. A failed sync is logged the same way, and the new status is kept. - Deleting.
onDeletinglooks the issue up the same way and closes it before the record goes. If the tracker fails, theDELETEanswers502and keeps the record: retry it once the tracker is back. The comment is left once, even across retries. - Deleting a whole project. The project's issues are listed first, and the delete is refused when the listing stops at
maxListedPageswith issues left (see how issues are found again). They are then handled one after the other, with up to three requests each: close the issue if it is open, read its comments, comment. A project with many issues can therefore hit the tracker's rate limit (GitHub allows about 80 content-creating requests a minute) or a serverless function's time limit. Every record is then kept: theDELETEanswers502when the tracker refuses a request, or the platform's own timeout error (504on Vercel, for example) when the function is stopped. After a rate limit, retry a few minutes later: an issue already closed and commented costs a single read, so each attempt gets further. A time limit is different: every attempt reads the comments of the issues already handled again, so it never handles more issues than one run has time for, and retrying a project past that size never succeeds. Delete its feedback one at a time instead, or run that delete through a handler without these hooks and close its issues yourself. - Slow answers. The widget gives up on a request after 10 seconds and retries it, so a status change whose lookup lists many pages (its search failed) can show an error for a change the server still makes. A project delete gets 60 seconds and is never sent again; past that, the widget reports an error and reloads its list, which shows what the server removed. Keep
maxListedPagesto what the repository needs. - Concurrent requests. Within one server process, the hooks queue their tracker work: a feedback's status changes and deletes run in the order they came, after the creation of its issue, and a project delete runs after the work already started on that project. This holds for hooks built once, at module scope, as in the examples above. Separate instances (several serverless functions, say) can still interleave two requests on one feedback. In one process as in several, a feedback sent while its project is being deleted goes with the project, and its issue can be left open: its
POSTdoes not wait for the delete, which could not keep the issue from opening.
The built-in trackers throw two errors that a custom logger can tell apart: IssueTrackerRequestError for a failed tracker request, an answer that is not JSON or is cut short by the timeout included (it carries the method, path and status, never the token) and UnlabelledIssueError for an issue created without its siteping label. Match them with isIssueTrackerRequestError(error) and isUnlabelledIssueError(error), exported next to them, rather than instanceof: in CommonJS, each entry point bundles its own copy of the error classes.
How issues are found again
Each body starts with the marker <!-- siteping-feedback {"id":"…","project":"…"} -->, which GitHub and GitLab do not display. Only that first line is read, so feedback text that imitates it is ignored. Edit the rest of the issue as you like, but keep that line first. The deletion comment starts the same way, with <!-- siteping-feedback-deleted -->: a retried delete looks for that line, not for the comment's text. Any comment that starts with it counts, whoever wrote it: on a public repository, anyone can post one to keep the deletion comment off an issue, which is still closed.
Deployments that share a repository and a project name (staging and production, or a preview that copied the production .env) would find each other's issues, and a project delete on staging would close production's. Give each its own instance: the marker then ends with "instance":"staging", and the hooks only touch issues opened under the same name, an unnamed deployment only those without one. Issues opened before a deployment was named, or renamed, keep the old name.
To sync a status or delete one feedback, the tracker is first searched for the feedback id (GitHub's search API, GitLab's search parameter). If the search misses, the hooks list the first page of siteping issues, newest first: GitHub's search index lags a few seconds behind a new issue. A search that answered settles the rest, since it only misses issues too new for its index. When it failed (GitHub allows 30 searches a minute), or found more issues quoting the feedback id than it returned, the hooks list further. Deleting a whole project always lists every issue.
Reopening writes nothing when the issue is already open, and a delete does not close an issue already closed (it keeps its close reason). The index also lags behind a state change, so before skipping a write on the strength of a search hit, the GitHub tracker reads that issue itself: an Undo right after a resolve still reopens it.
The listing stops after maxListedPages pages of 100 issues, and it counts the SitePing issues of every project in the repository, closed ones included, so a repository outgrows it in time. Past that, the hooks do not guess. A project delete is refused with a 502 rather than leaving the older issues open, and so is a status sync or a delete whose issue the search did not settle and the listing did not reach. With the default of 10, the cap is the repository's 1,000 newest SitePing issues. Raise it for a larger backlog: only project deletes and the lookups the search does not settle list that far.
Only labelled issues count. On GitHub and GitLab, an outsider cannot label an issue, so they cannot make one pass for SitePing's.
Other trackers
Implement IssueTracker for Jira, Linear or an internal tool. The hooks keep everything that does not depend on the tracker: the format, the marker, and making deletion comments idempotent.
import type { IssueTracker } from "@siteping/integration-issues";
const tracker: IssueTracker = {
name: "Linear", // named in the hooks' own errors
// Store `body` exactly as given: its first line is the marker.
async createIssue({ title, body, labels }) {
return { key: "ENG-42", url: "https://linear.app/acme/issue/ENG-42" };
},
// resolved / wont_fix close the issue; open / in_progress reopen it.
async updateIssueStatus(reference, status) {},
async addComment(reference, body) {},
async listComments(reference) {
return []; // comment bodies, each first line as addComment received it
},
// Every SitePing issue whose body contains `marker`, closed ones included,
// newest first, no more than `maxPages` pages when it is set, and whether
// you stopped before the last one.
async findSitepingIssues(marker, { maxPages } = {}) {
return { issues: [], truncated: false }; // issues: { reference, body, isOpen }
},
// Optional, but without it lookups past your cap are refused (see below):
// a server-side search by feedback id, tried first, and whether it found
// more matches than it returned.
async searchSitepingIssues(feedbackId) {
return { issues: [], truncated: false };
},
// Optional: the issue as the tracker holds it now ({ reference, body, isOpen }).
// Implement it when the search answers from an index that can lag behind a
// state change: the hooks then read a search hit again before skipping a write.
async getIssue(reference) {
return { reference, body: "", isOpen: true };
},
};Throw when a call fails, and the failure rules above apply. Trackers that do not speak Markdown can shape the body with formatIssue.
Without searchSitepingIssues, nothing settles a lookup past the newest page: every status change or delete whose issue is not there lists up to your cap, and once the tracker holds more SitePing issues than that, one whose issue is not listed is refused. That includes a feedback that never got an issue, which then cannot be deleted. Provide a search whenever the tracker has one.
Syncing the other way, so that closing an issue resolves its feedback, needs a tracker webhook handler and is not built yet (#318).
Discussion threads
Comments on a feedback, stored next to it and served by the same endpoint — with the team role and reviewer emails guarded by your access policy.
Choosing an adapter
Where your feedback lives — Prisma or Drizzle for production, memory for tests and demos, localStorage for client-only setups.