Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Enhance site configuration options in API and documentation

Bill Yangbc33a60d97d3
diff --git a/client/src/app/[site]/api-playground/utils/endpointConfig.ts b/client/src/app/[site]/api-playground/utils/endpointConfig.ts
index 55346606c..194eb9623 100644
--- a/client/src/app/[site]/api-playground/utils/endpointConfig.ts
+++ b/client/src/app/[site]/api-playground/utils/endpointConfig.ts
@@ -106,6 +106,21 @@ export const endpointCategories: EndpointCategory[] = [
name: "My Website",
public: false,
blockBots: true,
+ saltUserIds: false,
+ excludedIPs: [],
+ excludedCountries: [],
+ sessionReplay: false,
+ webVitals: false,
+ trackErrors: false,
+ trackOutbound: true,
+ trackUrlParams: true,
+ trackInitialPageView: true,
+ trackSpaNavigation: true,
+ trackIp: false,
+ trackButtonClicks: false,
+ trackCopy: false,
+ trackFormInteractions: false,
+ tags: [],
},
},
{
diff --git a/docs/content/docs/api/organizations.mdx b/docs/content/docs/api/organizations.mdx
index c86140a8f..77c64d5e0 100644
--- a/docs/content/docs/api/organizations.mdx
+++ b/docs/content/docs/api/organizations.mdx
@@ -449,6 +449,76 @@ Creates a new site within an organization. Requires admin or owner role in the o
type: 'boolean',
default: true,
},
+ excludedIPs: {
+ description: 'Array of IP addresses to exclude from tracking',
+ type: 'string[]',
+ default: '[]',
+ },
+ excludedCountries: {
+ description: 'Array of ISO country codes to exclude (e.g., ["US", "GB"])',
+ type: 'string[]',
+ default: '[]',
+ },
+ sessionReplay: {
+ description: 'Enable session replay recording',
+ type: 'boolean',
+ default: false,
+ },
+ webVitals: {
+ description: 'Enable Core Web Vitals tracking',
+ type: 'boolean',
+ default: false,
+ },
+ trackErrors: {
+ description: 'Enable JavaScript error tracking',
+ type: 'boolean',
+ default: false,
+ },
+ trackOutbound: {
+ description: 'Track outbound link clicks',
+ type: 'boolean',
+ default: true,
+ },
+ trackUrlParams: {
+ description: 'Track URL parameters (UTM, etc.)',
+ type: 'boolean',
+ default: true,
+ },
+ trackInitialPageView: {
+ description: 'Automatically track the initial page view',
+ type: 'boolean',
+ default: true,
+ },
+ trackSpaNavigation: {
+ description: 'Track SPA navigation events',
+ type: 'boolean',
+ default: true,
+ },
+ trackIp: {
+ description: 'Store visitor IP addresses',
+ type: 'boolean',
+ default: false,
+ },
+ trackButtonClicks: {
+ description: 'Track button click events',
+ type: 'boolean',
+ default: false,
+ },
+ trackCopy: {
+ description: 'Track copy events',
+ type: 'boolean',
+ default: false,
+ },
+ trackFormInteractions: {
+ description: 'Track form interaction events',
+ type: 'boolean',
+ default: false,
+ },
+ tags: {
+ description: 'Array of tags for organizing the site',
+ type: 'string[]',
+ default: '[]',
+ },
}}
/>
@@ -494,6 +564,62 @@ Returns the created site object with the assigned `siteId`.
description: 'Whether bot traffic is blocked',
type: 'boolean',
},
+ excludedIPs: {
+ description: 'Excluded IP addresses',
+ type: 'string[]',
+ },
+ excludedCountries: {
+ description: 'Excluded country codes',
+ type: 'string[]',
+ },
+ sessionReplay: {
+ description: 'Whether session replay is enabled',
+ type: 'boolean',
+ },
+ webVitals: {
+ description: 'Whether Web Vitals tracking is enabled',
+ type: 'boolean',
+ },
+ trackErrors: {
+ description: 'Whether error tracking is enabled',
+ type: 'boolean',
+ },
+ trackOutbound: {
+ description: 'Whether outbound link tracking is enabled',
+ type: 'boolean',
+ },
+ trackUrlParams: {
+ description: 'Whether URL parameter tracking is enabled',
+ type: 'boolean',
+ },
+ trackInitialPageView: {
+ description: 'Whether initial page view is tracked automatically',
+ type: 'boolean',
+ },
+ trackSpaNavigation: {
+ description: 'Whether SPA navigation is tracked',
+ type: 'boolean',
+ },
+ trackIp: {
+ description: 'Whether IP addresses are stored',
+ type: 'boolean',
+ },
+ trackButtonClicks: {
+ description: 'Whether button clicks are tracked',
+ type: 'boolean',
+ },
+ trackCopy: {
+ description: 'Whether copy events are tracked',
+ type: 'boolean',
+ },
+ trackFormInteractions: {
+ description: 'Whether form interactions are tracked',
+ type: 'boolean',
+ },
+ tags: {
+ description: 'Site tags',
+ type: 'string[]',
+ },
}}
/>
@@ -675,7 +801,21 @@ var data = await response.Content.ReadAsStringAsync();
"createdBy": "user_xyz789",
"public": false,
"saltUserIds": false,
- "blockBots": true
+ "blockBots": true,
+ "excludedIPs": [],
+ "excludedCountries": [],
+ "sessionReplay": false,
+ "webVitals": false,
+ "trackErrors": false,
+ "trackOutbound": true,
+ "trackUrlParams": true,
+ "trackInitialPageView": true,
+ "trackSpaNavigation": true,
+ "trackIp": false,
+ "trackButtonClicks": false,
+ "trackCopy": false,
+ "trackFormInteractions": false,
+ "tags": []
}
```
diff --git a/server/src/api/sites/addSite.ts b/server/src/api/sites/addSite.ts
index 296e71d2a..e9a326785 100644
--- a/server/src/api/sites/addSite.ts
+++ b/server/src/api/sites/addSite.ts
@@ -2,6 +2,8 @@ import { randomBytes } from "crypto";
import { FastifyReply, FastifyRequest } from "fastify";
import { db } from "../../db/postgres/postgres.js";
import { sites } from "../../db/postgres/schema.js";
+import { IS_CLOUD } from "../../lib/const.js";
+import { getSubscriptionInner } from "../stripe/getSubscription.js";
export async function addSite(
request: FastifyRequest<{
@@ -14,12 +16,46 @@ export async function addSite(
public?: boolean;
saltUserIds?: boolean;
blockBots?: boolean;
+ excludedIPs?: string[];
+ excludedCountries?: string[];
+ sessionReplay?: boolean;
+ webVitals?: boolean;
+ trackErrors?: boolean;
+ trackOutbound?: boolean;
+ trackUrlParams?: boolean;
+ trackInitialPageView?: boolean;
+ trackSpaNavigation?: boolean;
+ trackIp?: boolean;
+ trackButtonClicks?: boolean;
+ trackCopy?: boolean;
+ trackFormInteractions?: boolean;
+ tags?: string[];
};
}>,
reply: FastifyReply
) {
const { organizationId } = request.params;
- const { domain, name, public: isPublic, saltUserIds, blockBots } = request.body;
+ const {
+ domain,
+ name,
+ public: isPublic,
+ saltUserIds,
+ blockBots,
+ excludedIPs,
+ excludedCountries,
+ sessionReplay,
+ webVitals,
+ trackErrors,
+ trackOutbound,
+ trackUrlParams,
+ trackInitialPageView,
+ trackSpaNavigation,
+ trackIp,
+ trackButtonClicks,
+ trackCopy,
+ trackFormInteractions,
+ tags,
+ } = request.body;
// Strip protocol and trailing slash before validation
const cleanedDomain = domain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
@@ -35,6 +71,24 @@ export async function addSite(
try {
const userId = request.user?.id;
+ if (IS_CLOUD) {
+ const subscription = await getSubscriptionInner(organizationId);
+
+ if (sessionReplay && !subscription?.isPro) {
+ return reply.status(403).send({
+ error: "Session replay requires a Pro subscription",
+ });
+ }
+
+ const standardFeatures = { webVitals, trackErrors, trackButtonClicks, trackCopy, trackFormInteractions };
+ const requestedStandard = Object.entries(standardFeatures).filter(([, v]) => v);
+ if (requestedStandard.length > 0 && subscription?.status !== "active") {
+ return reply.status(403).send({
+ error: `The following features require an active subscription: ${requestedStandard.map(([k]) => k).join(", ")}`,
+ });
+ }
+ }
+
const id = randomBytes(6).toString("hex");
// Create the new site
@@ -49,6 +103,20 @@ export async function addSite(
public: isPublic || false,
saltUserIds: saltUserIds || false,
blockBots: blockBots === undefined ? true : blockBots,
+ ...(excludedIPs !== undefined && { excludedIPs }),
+ ...(excludedCountries !== undefined && { excludedCountries }),
+ ...(sessionReplay !== undefined && { sessionReplay }),
+ ...(webVitals !== undefined && { webVitals }),
+ ...(trackErrors !== undefined && { trackErrors }),
+ ...(trackOutbound !== undefined && { trackOutbound }),
+ ...(trackUrlParams !== undefined && { trackUrlParams }),
+ ...(trackInitialPageView !== undefined && { trackInitialPageView }),
+ ...(trackSpaNavigation !== undefined && { trackSpaNavigation }),
+ ...(trackIp !== undefined && { trackIp }),
+ ...(trackButtonClicks !== undefined && { trackButtonClicks }),
+ ...(trackCopy !== undefined && { trackCopy }),
+ ...(trackFormInteractions !== undefined && { trackFormInteractions }),
+ ...(tags !== undefined && { tags }),
})
.returning();