Skip to content

Commit f452756

Browse files
committed
fix(sdk): use neutral sync endpoints in sdk to prevent ad-blocker
1 parent 125b6c3 commit f452756

5 files changed

Lines changed: 13 additions & 5 deletions

File tree

.changeset/large-spiders-feel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@flagix/js-sdk": minor
3+
---
4+
5+
migrated internal tracking and evaluation endpoints to a generic /api/sync path. This change is to improve the SDK reliability by bypassing aggressive tracking filters in browser privacy extensions and ad-blockers

apps/api/src/app.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import flagRoutes from "@/routes/flag/route";
88
import flagConfigRoutes from "@/routes/flag-config/route";
99
import projectRoutes from "@/routes/project/route";
1010
import sseRoutes from "@/routes/sse/route";
11-
import trackRoutes from "@/routes/track/route";
11+
import trackRoutes from "@/routes/sync/route";
1212

1313
const createApp = (): Express => {
1414
const app: Express = express();
@@ -23,7 +23,10 @@ const createApp = (): Express => {
2323

2424
app.use("/api/flag-config", flagConfigRoutes);
2525
app.use("/api/sse", sseRoutes);
26-
app.use("/api/track", trackRoutes);
26+
27+
// this route ideally should be `track` but is named `sync` because ad-blockers block routes with "track" in them
28+
// the route handles tracking events from the SDK
29+
app.use("/api/sync", trackRoutes);
2730

2831
app.use(requireAuth);
2932

apps/api/src/config/cors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { CorsOptionsDelegate } from "cors";
22
import type { Request } from "express";
33
import { env } from "@/config/env";
44

5-
const SDK_PREFIXES = ["/api/flag-config", "/api/track", "/api/sse"];
5+
const SDK_PREFIXES = ["/api/flag-config", "/api/sync", "/api/sse"];
66
const ALLOWED_ADMIN_ORIGINS = [env.FRONTEND_URL, "http://localhost:3000"];
77

88
export const corsOptions: CorsOptionsDelegate = (req, callback) => {

sdk/javascript/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export class FlagixClient {
412412
properties?: Record<string, unknown>,
413413
contextOverrides?: EvaluationContext
414414
): void {
415-
const url = `${this.apiBaseUrl}/api/track/event`;
415+
const url = `${this.apiBaseUrl}/api/sync/event`;
416416

417417
const finalContext = { ...this.context, ...contextOverrides };
418418
const distinctId = resolveIdentifier(finalContext);
@@ -466,7 +466,7 @@ export class FlagixClient {
466466
result: FlagVariation,
467467
context: EvaluationContext
468468
): void {
469-
const url = `${this.apiBaseUrl}/api/track/evaluation`;
469+
const url = `${this.apiBaseUrl}/api/sync/evaluation`;
470470

471471
const distinctId = resolveIdentifier(context);
472472

0 commit comments

Comments
 (0)