diff --git a/apps/web-roo-code/src/app/pr-fixer/PrFixerContent.tsx b/apps/web-roo-code/src/app/pr-fixer/PrFixerContent.tsx
index 285a28e6f6eb..48bb5abaa6a9 100644
--- a/apps/web-roo-code/src/app/pr-fixer/PrFixerContent.tsx
+++ b/apps/web-roo-code/src/app/pr-fixer/PrFixerContent.tsx
@@ -112,7 +112,10 @@ export function PrFixerContent() {
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
target="_blank"
rel="noopener noreferrer"
- onClick={trackGoogleAdsConversion}
+ onClick={(e) => {
+ e.preventDefault()
+ trackGoogleAdsConversion(EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO)
+ }}
className="flex w-full items-center justify-center">
Start 14-day Free Trial
@@ -225,7 +228,10 @@ export function PrFixerContent() {
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
target="_blank"
rel="noopener noreferrer"
- onClick={trackGoogleAdsConversion}
+ onClick={(e) => {
+ e.preventDefault()
+ trackGoogleAdsConversion(EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO)
+ }}
className="flex items-center justify-center">
Start 14-day Free Trial
diff --git a/apps/web-roo-code/src/app/reviewer/ReviewerContent.tsx b/apps/web-roo-code/src/app/reviewer/ReviewerContent.tsx
index 3f5a1cf12a01..8425f727d93a 100644
--- a/apps/web-roo-code/src/app/reviewer/ReviewerContent.tsx
+++ b/apps/web-roo-code/src/app/reviewer/ReviewerContent.tsx
@@ -127,7 +127,10 @@ export function ReviewerContent() {
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
target="_blank"
rel="noopener noreferrer"
- onClick={trackGoogleAdsConversion}
+ onClick={(e) => {
+ e.preventDefault()
+ trackGoogleAdsConversion(EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO)
+ }}
className="flex w-full items-center justify-center">
Start 14-day Free Trial
@@ -281,7 +284,10 @@ export function ReviewerContent() {
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
target="_blank"
rel="noopener noreferrer"
- onClick={trackGoogleAdsConversion}
+ onClick={(e) => {
+ e.preventDefault()
+ trackGoogleAdsConversion(EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO)
+ }}
className="flex items-center justify-center">
Start 14-day Free Trial
diff --git a/apps/web-roo-code/src/lib/analytics/google-ads.ts b/apps/web-roo-code/src/lib/analytics/google-ads.ts
index 29ced92e99ea..09fa6f8b50c7 100644
--- a/apps/web-roo-code/src/lib/analytics/google-ads.ts
+++ b/apps/web-roo-code/src/lib/analytics/google-ads.ts
@@ -3,15 +3,40 @@
*/
/**
- * Track a Google Ads conversion event
- * This should only be called after user consent has been given
+ * Track a Google Ads conversion event with optional navigation callback
+ * This ensures the conversion ping completes before navigation occurs
+ *
+ * @param targetUrl - Optional URL to navigate to after conversion is tracked
+ *
+ * @example
+ * // Track conversion and navigate
+ * trackGoogleAdsConversion("https://app.roocode.com")
+ *
+ * @example
+ * // Track conversion without navigation
+ * trackGoogleAdsConversion()
*/
-export function trackGoogleAdsConversion() {
+export function trackGoogleAdsConversion(targetUrl?: string) {
if (typeof window !== "undefined" && window.gtag) {
+ // Callback to handle navigation after conversion tracking
+ const callback = () => {
+ if (targetUrl) {
+ window.location.href = targetUrl
+ }
+ }
+
window.gtag("event", "conversion", {
send_to: "AW-17391954825/VtOZCJe_77MbEInXkOVA",
value: 10.0,
currency: "USD",
+ event_callback: callback,
})
+
+ // Fallback timeout in case event_callback doesn't fire (network issues, etc.)
+ // This ensures navigation still happens even if tracking fails
+ setTimeout(callback, 1000)
+ } else if (targetUrl) {
+ // If gtag is not available, navigate immediately
+ window.location.href = targetUrl
}
}