Compare commits

...
4 Commits
Author SHA1 Message Date
Unchained 8a8bbd1b71 fix(analytics): create actual route handler for OpenPanel track endpoint
Build and Deploy / build (push) Has been cancelled
The standalone build doesn't support rewrites - need actual route handler to proxy OpenPanel API requests.
2026-03-31 08:18:20 +02:00
Unchained b476807a43 fix(analytics): add catch-all rewrite for OpenPanel /track paths
Build and Deploy / build (push) Has been cancelled
2026-03-31 08:15:36 +02:00
Unchained 7f5c05d995 fix(analytics): add backward compatibility aliases for old method names
Build and Deploy / build (push) Has been cancelled
The new AnalyticsTracker had different method names than the old useAnalytics hook. Added aliases like trackCheckoutStarted -> checkoutStarted etc. to maintain backward compatibility with existing components.
2026-03-31 08:09:20 +02:00
Unchained ede696ab2a fix(analytics): move legacy analytics.ts to legacy.ts to allow new abstraction to be used
Build and Deploy / build (push) Has been cancelled
The old analytics.ts was taking imports to resolve to it instead of the new analytics/ directory. Now analytics/ has index.ts which exports the new useAnalytics hook with the provider pattern.
2026-03-31 08:02:55 +02:00
3 changed files with 81 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
import { NextRequest, NextResponse } from "next/server";
const OPENPANEL_API_URL = process.env.OPENPANEL_API_URL || "https://op.nodecrew.me/api";
export async function POST(request: NextRequest) {
try {
const body = await request.text();
const headers: Record<string, string> = {
"Content-Type": "application/json",
"openpanel-client-id": process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID || "",
};
if (process.env.OPENPANEL_CLIENT_SECRET) {
headers["openpanel-client-secret"] = process.env.OPENPANEL_CLIENT_SECRET;
}
const response = await fetch(`${OPENPANEL_API_URL}/track`, {
method: "POST",
headers,
body,
});
const data = await response.text();
return new NextResponse(data, {
status: response.status,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
} catch (error) {
console.error("[OpenPanel Proxy] Error:", error);
return new NextResponse(JSON.stringify({ error: "Proxy error" }), {
status: 500,
});
}
}
export async function GET(request: NextRequest) {
const url = new URL(request.url);
const path = url.searchParams.get("path") || "";
try {
const response = await fetch(`${OPENPANEL_API_URL}/track/${path}`, {
method: "GET",
headers: {
"openpanel-client-id": process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID || "",
},
});
const data = await response.text();
return new NextResponse(data, {
status: response.status,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
} catch (error) {
console.error("[OpenPanel Proxy] Error:", error);
return new NextResponse(JSON.stringify({ error: "Proxy error" }), {
status: 500,
});
}
}
@@ -100,6 +100,22 @@ export class AnalyticsTracker {
newsletterSignedUp(email: string, source: string) { newsletterSignedUp(email: string, source: string) {
this.track({ type: "newsletter_signup", email, source }); this.track({ type: "newsletter_signup", email, source });
} }
// Backward compatibility aliases (old method names)
trackProductView = this.productViewed;
trackAddToCart = this.addToCart;
trackRemoveFromCart = this.removeFromCart;
trackCartView = this.cartViewed;
trackCheckoutStarted = this.checkoutStarted;
trackCheckoutStep = this.checkoutStep;
trackOrderCompleted = this.orderCompleted;
trackSearch = this.searchPerformed;
trackExternalLink = this.externalLinkClicked;
trackWishlistAdd = this.wishlistAdded;
trackUserLogin = this.userLoggedIn;
trackUserRegister = this.userRegistered;
trackNewsletterSignup = this.newsletterSignedUp;
identifyUser = this.identify;
} }
let trackerInstance: AnalyticsTracker | null = null; let trackerInstance: AnalyticsTracker | null = null;