feat(analytics): set up GA4 + Tag Manager with conversion events#122
Conversation
Every public page now emits Open Graph and Twitter card tags (title, description, url, image) so links render branded previews on LinkedIn, Slack, WhatsApp and X. - Add a branded 1200x630 social card generated with next/og, served site-wide via app/opengraph-image and reused for app/twitter-image. - Add buildMetadata() helper that produces matching title/description/ canonical plus OG and Twitter card objects for each page. - Route home and auth pages through the helper; add OG/Twitter defaults to the root layout for inheritance. Refs #106
Footer links now resolve to real pages or anchors instead of placeholders that fell back to the homepage, and the previously missing contact and legal pages exist. - Footer: grouped Product/Company/Legal navigation with a real contact email, on-page anchors (#how-it-works, #faq), the parent company site, and links to the new pages. - Add /contact (indexable) with a real, monitored address. - Add /privacy and /terms minimal legal pages (noindex,follow). - Add SitePage shell for consistent standalone-page layout. Refs #112
Serve a robots.txt that allows public pages, blocks the API and gated admin/user areas, and points crawlers to the sitemap. Refs #107
Serve a sitemap.xml listing the public, indexable pages with last-modified, change frequency, and priority. The page list lives in a central publicRoutes constant so adding a public page updates the sitemap from one place; gated, admin, and API routes are excluded. Refs #108
Emit JSON-LD on every page so search and AI answer engines can identify the product, the organization behind it, and its offering. - Site-wide @graph (Organization, WebSite, SoftwareApplication) rendered from the root layout. - Organization mirrors Ajared coverage: legal name, two locations (Toronto, Abuja) with addresses and geo, contact point, and sameAs. - SoftwareApplication describes Retailytics with category, offer (free trial), and a feature list. - FAQPage emitted on the home page from the existing FAQ content. - BreadcrumbList on standalone pages via SitePage. Refs #109
Serve an llms.txt manifest at the site root so AI crawlers know what Retailytics is and which pages are authoritative. Includes a product summary, the core pages, a company description, and key features, generated from the shared site config to stay in sync. Refs #110
Wire Google Tag Manager (the GA4 delivery vehicle) into every page without blocking page load, track key conversion actions, and add a Search Console verification hook. Everything stays inert until the IDs are provisioned (see #113). - GoogleTagManager: afterInteractive GTM loader + noscript fallback, rendered only when NEXT_PUBLIC_GTM_ID is set. - Search Console verification via metadata when GOOGLE_SITE_VERIFICATION is set. - sendGTMEvent dataLayer helper, plus event instrumentation: - cta_click on the hero and CTA-section primary buttons (sign-up handoff to /register), with cta_location. - contact_click on the footer and contact-page email links. - engaged (meaningful engagement) after 30s or 50% scroll on the home page. Refs #111
|
Claude finished @prudentbird's task —— View job PR Review: GA4 + Tag Manager Analytics ImplementationReview Checklist
✅ Overall AssessmentExcellent implementation that follows Next.js and React best practices. The code is well-structured, type-safe, and follows a clean separation of concerns. The analytics integration is properly implemented with good security practices. 🔍 Detailed Review🏗️ Architecture & Code QualityScore: 9/10
🔒 Security ConsiderationsScore: 10/10
⚡ Performance ConsiderationsScore: 9/10 Excellent:
Minor Optimization Opportunity:
// In engagement-tracker.tsx:21-24, consider:
const onScroll = debounce(() => {
const scrolled = window.scrollY / (document.body.scrollHeight - window.innerHeight || 1);
if (scrolled >= ENGAGEMENT_SCROLL_RATIO) fire('scroll');
}, 100);🧪 Test Coverage NeedsScore: 6/10 Missing Test Cases:
Suggested Test Structure: // __tests__/analytics/google-tag-manager.test.tsx
describe('GoogleTagManager', () => {
it('renders script when GTM_ID is set', () => {})
it('returns null when GTM_ID is not set', () => {})
})📱 Browser CompatibilityScore: 10/10
🔧 Implementation DetailsStrengths:
Minor Suggestions:
📋 Action ItemsRequired Changes: ❌ NoneThis PR is ready to merge as-is. Recommended Improvements (Future PRs):
🚀 Deployment Readiness✅ Safe to merge - The implementation properly handles missing environment variables and won't break in any environment. ✅ Production Ready - Follows Google's recommended GTM implementation patterns with proper fallbacks. Final Verdict: LGTM 🎉 This is a high-quality implementation that demonstrates excellent React/Next.js practices. The analytics integration is secure, performant, and maintainable. |
Summary
Brings analytics to the marketing surface via Google Tag Manager (GA4's delivery vehicle), tracks key conversions, and adds a Search Console verification hook. All of it stays inert until IDs are provisioned (#113), so merging is safe.
GoogleTagManager) —next/scriptafterInteractive(non-blocking) +<noscript>iframe fallback. Renders only whenNEXT_PUBLIC_GTM_IDis set.GOOGLE_SITE_VERIFICATIONis set.sendGTMEventdataLayerhelper:cta_click— hero + CTA-section primary buttons (sign-up handoff to/register), tagged withcta_location.contact_click— footer + contact-page email links.engaged— meaningful engagement, fired once after 30s or 50% scroll on the home page.NEXT_PUBLIC_GTM_ID,GOOGLE_SITE_VERIFICATION(both optional).Done when (issue #111)
Validation
npm run typecheck✅ /npm run build✅GTM-TEST123+ verification token: confirmed the GTM script, the<noscript>iframe, and thegoogle-site-verificationmeta all render. With no env set: confirmed fully inert.Notes
Final PR in the SEO stack (targets
feat/geo-110-llms-txt). Real GTM/GA4 IDs and the verification token are provisioned in ops issue #113. Project already uses Vercel Analytics + Mixpanel; this adds GA4/GTM alongside them per the issue.Closes #111