Skip to content

fix: track order clickthroughs in static export#27

Merged
jontsai merged 3 commits into
masterfrom
feat/ga-html-and-order-click-tracking
May 6, 2026
Merged

fix: track order clickthroughs in static export#27
jontsai merged 3 commits into
masterfrom
feat/ga-html-and-order-click-tracking

Conversation

@jontsai

@jontsai jontsai commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Move Google Analytics setup into _document so the static GitHub Pages export emits the GA loader/config in HTML.
  • Add a shared trackOutboundClick helper for outbound order-click events with destination metadata and beacon transport.
  • Track Skillet'z and Tea-Rek'z online-order CTA clicks.
  • Delay the Tea-Rek'z auto-redirect until GA confirms the event callback, with event_timeout plus a 1.2s fallback so users do not get stuck.

Validation

  • npm run lint — passes; existing @next/next/no-img-element warnings remain in unrelated blog/menu print files.
  • make build — passes; existing warnings remain for image usage, large /tv and /menu page data, and npm audit summary.
  • GitHub Actions build — passed on the latest push.

Review notes

  • Addressed Copilot feedback on the Tea-Rek'z redirect racing the async analytics event.

Copilot AI review requested due to automatic review settings April 24, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make Google Analytics reliably present in statically exported HTML (for GitHub Pages) and add outbound click tracking for “order” links.

Changes:

  • Added a trackOutboundClick helper that emits an outbound click event via window.gtag.
  • Removed the GoogleAnalytics component injection from the Pages Router _app.js.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/utils/analytics.ts Introduces outbound click tracking helper using gtag.
src/pages/_app.js Removes Google Analytics component from the app wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/analytics.ts Outdated
Comment on lines +13 to +16
export function trackOutboundClick({ destination, label, location }: TrackOutboundClickParams) {
if (typeof window === 'undefined' || typeof window.gtag !== 'function') {
return;
}

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trackOutboundClick is introduced here, but it is not referenced anywhere else in the codebase (only definition found). If the intent is to track clicks on order links, this needs to be called from the relevant link components/pages; otherwise this is dead code and the feature described in the PR won’t be delivered.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. trackOutboundClick is now wired into /order-online partner links and the Tea-Rekz order flow (both the fallback link and the redirect page).

Comment thread src/utils/analytics.ts Outdated
Comment on lines +1 to +3
declare global {
interface Window {
gtag?: (...args: any[]) => void;

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.gtag is typed with any[], which defeats type-safety and can mask incorrect event parameter usage. Consider using a stronger type (e.g. via @types/gtag.js / Gtag.Gtag) or defining a minimal gtag call signature that matches the events you send.

Suggested change
declare global {
interface Window {
gtag?: (...args: any[]) => void;
interface OutboundClickGtagParams {
event_category: 'outbound';
event_label: string;
link_url: string;
link_domain: string | null;
page_location: string;
transport_type: 'beacon';
}
type Gtag = (command: 'event', eventName: 'click', params: OutboundClickGtagParams) => void;
declare global {
interface Window {
gtag?: Gtag;

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I replaced the loose any[] signature with a minimal typed Gtag function signature tailored to the outbound click event we send.

Comment thread src/utils/analytics.ts Outdated
Comment on lines +7 to +13
interface TrackOutboundClickParams {
destination: string;
label: string;
location: string;
}

export function trackOutboundClick({ destination, label, location }: TrackOutboundClickParams) {

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name location is easy to confuse with the global window.location and doesn’t convey that this should be the page URL. Consider renaming to something like pageLocation (or making it optional and deriving from window.location.href inside the function) for clearer call sites.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I renamed the parameter to pageLocation and made it optional, defaulting to window.location.href inside the helper.

Comment thread src/pages/_app.js
Comment on lines 1 to 9
import StructuredData from '@/components/StructuredData';

import '@/styles/globals.css';

export default function App({ Component, pageProps }) {
return (
<>
<GoogleAnalytics measurementId={ANALYTICS.google.measurementId} />
<StructuredData />
<Component {...pageProps} />

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GoogleAnalytics was removed from _app.js, but there is no replacement GA/gtag initialization anywhere else in the repo (no googletagmanager.com/gtag script or gtag('config', ...) found). As a result, window.gtag will never be defined and analytics/click tracking won’t fire. Add the GA script/config in a place that is included in the static export output (e.g., _document.js via next/script, or another exported HTML entrypoint) and wire it to ANALYTICS.google.measurementId.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. GA is now initialized from _document.js, so the gtag.js loader and gtag('config', measurementId) are present in the statically exported HTML as well.

@jontsai jontsai force-pushed the feat/ga-html-and-order-click-tracking branch from 716857d to 3d899cf Compare May 6, 2026 09:05
Copilot AI review requested due to automatic review settings May 6, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/pages/order-online-tearekz.tsx Outdated
@jontsai jontsai changed the title feat: track order clickthroughs with Google Analytics fix: track order clickthroughs in static export May 6, 2026
@jontsai jontsai merged commit 363c6d2 into master May 6, 2026
1 check passed
@jontsai jontsai deleted the feat/ga-html-and-order-click-tracking branch May 6, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants