Skip to main content

Analytics Setup — PhotoSwipe Pro with AI SEO

Current Status

Google Analytics 4 (GA4) is already installed via @docusaurus/plugin-google-gtag

⚠️ But using placeholder tracking ID: G-57MLE6HBT9

You need to replace this with your own tracking ID to start collecting data.


Why Analytics Matters

Critical for revenue optimization:

  1. Track conversions — How many visitors buy?
  2. Measure funnel — Where do people drop off?
  3. Calculate ROI — Which marketing channels work?
  4. Optimize pricing — Test different price points
  5. Improve UX — See what users actually do

Without analytics, you're flying blind!


Step 1: Create GA4 Property

  1. Go to https://analytics.google.com
  2. Click "Admin" (gear icon, bottom left)
  3. Click "Create Property"
  4. Enter property details:
    • Property name: PhotoSwipe Pro
    • Time zone: Your timezone
    • Currency: USD
  5. Click "Next"
  6. Choose business details (optional)
  7. Click "Create"

Step 2: Create Data Stream

  1. In the property, click "Data Streams"
  2. Click "Add stream" → "Web"
  3. Enter your URL:
  4. Enable Enhanced Measurement (recommended)
  5. Click "Create stream"

Step 3: Get Tracking ID

  1. Copy the Measurement ID (format: G-XXXXXXXXXX)
  2. This is what you'll use in the config

Step 4: Update Docusaurus Config

File: demo-docs-website/docusaurus.config.js

plugins: [
[
'@docusaurus/plugin-google-gtag',
{
trackingID: 'G-XXXXXXXXXX', // ← Replace with your tracking ID
anonymizeIP: true, // Optional: GDPR compliance
},
],
],

Step 5: Deploy

# Redeploy to apply changes
vercel --prod

Step 6: Verify

  1. Visit your site: https://your-site.vercel.app
  2. Open browser DevTools → Network tab
  3. Look for requests to google-analytics.com/g/collect
  4. Check GA4 real-time reports (Admin → Reports → Realtime)

Events to Track (Pre-configured)

GA4 automatically tracks:

Page views — Every page visit ✅ Scroll depth — How far users scroll ✅ Outbound clicks — Clicks to external sites ✅ File downloads — Pro ZIP downloads ✅ Video engagement — If you add videos ✅ Site search — Docs site search


Custom Events to Add (High Priority)

1. Checkout Button Click

Where: /checkout page

Add to CheckoutHandler component:

// demo-docs-website/src/components/CheckoutHandler/index.tsx

const handleSelectTier = async (tierId: string) => {
// Track checkout initiation
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', 'begin_checkout', {
currency: 'USD',
value: tierId === 'site' ? 99 : 299,
items: [{
item_id: tierId,
item_name: `PhotoSwipe Pro ${tierId} License`,
}],
});
}

// ... existing checkout logic
};

2. License Key Copied

Where: /customer-portal page

Add to CustomerPortal component:

// demo-docs-website/src/components/CustomerPortal/index.tsx

onClick={() => {
navigator.clipboard.writeText(license.key);

// Track license key copy
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', 'license_key_copied', {
license_tier: license.tier,
});
}

alert('License key copied to clipboard!');
}}

3. AI Demo Usage

Where: /pro page demo

Add to ProDemo component:

// demo-docs-website/src/components/ProDemo/index.js

onClick={async () => {
setError('');

// Track AI generation attempt
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', 'ai_demo_used', {
has_license_key: !!licenseKey && isValid,
image_url: img.src,
});
}

try {
const res = await ai({ slide: { src: img.src, title: img.title }, licenseKey });
setGenerated((g) => ({ ...g, [img.src]: res }));

// Track successful generation
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', 'ai_generation_success', {
image_url: img.src,
});
}
} catch (err) {
// ... error handling
}
}}

4. Purchase Complete (Server-side)

Where: Backend after LemonSqueezy webhook

Add to webhook handler:

// server/lemonsqueezy/webhook.js (future)

app.post('/api/webhook/lemonsqueezy', async (req, res) => {
const event = req.body;

if (event.event_name === 'order_created') {
// Send conversion event to GA4
// Use Measurement Protocol API
await fetch(`https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_SECRET`, {
method: 'POST',
body: JSON.stringify({
client_id: event.meta.custom_data?.client_id || 'server',
events: [{
name: 'purchase',
params: {
transaction_id: event.data.id,
value: event.data.attributes.total / 100,
currency: 'USD',
items: [{
item_id: event.data.attributes.first_order_item.variant_id,
item_name: event.data.attributes.first_order_item.product_name,
price: event.data.attributes.total / 100,
}],
},
}],
}),
});
}

res.json({ received: true });
});

Key Metrics to Monitor

Revenue Metrics

In GA4: Monetization → Overview

  1. Revenue — Total sales
  2. Average purchase revenue — Revenue per order
  3. Purchase-to-detail rate — Checkout → Purchase %
  4. Purchases — Total orders

Traffic Metrics

In GA4: Reports → Acquisition

  1. Users — Unique visitors
  2. Sessions — Total visits
  3. Session duration — Time on site
  4. Bounce rate — Single-page visits %

Conversion Funnel

In GA4: Explore → Funnel Exploration

Create funnel:

1. Landing page (/pro or /)

2. Visit /checkout

3. Click "Buy Now" (begin_checkout event)

4. Purchase (purchase event)

Track drop-off at each step!

Goal: Calculate Conversion Rate

Conversion Rate = Purchases / Checkout Page Views

Example:
- 1,000 visitors to /checkout
- 20 purchases
- Conversion rate: 2%

Revenue:
- 12 Site ($99) + 8 Agency ($299) = $3,580

Alternative: Plausible Analytics (Privacy-Friendly)

If you prefer privacy-focused analytics:

Why Plausible?

No cookies — GDPR compliant by default ✅ Lightweight — <1KB script (GA4 is ~45KB) ✅ Simple UI — Easier to understand ✅ Privacy-first — No cross-site tracking

Paid — $9/month (vs GA4 free) ❌ Less features — No advanced funnels

Setup Plausible

  1. Sign up at https://plausible.io
  2. Add your domain
  3. Get tracking script
  4. Add to docusaurus.config.js:
scripts: [
{
src: 'https://plausible.io/js/script.js',
'data-domain': 'photoswipe-pro.com',
defer: true,
},
],

Custom events:

// Track checkout
window.plausible('Checkout', { props: { tier: 'site' } });

// Track purchase
window.plausible('Purchase', { props: { value: 99 } });

Analytics Checklist

Phase 1: Launch (Critical)

  • Replace placeholder GA4 tracking ID
  • Verify tracking works in production
  • Set up conversion goals in GA4
  • Test purchase event tracking

Phase 2: Optimization (Week 2)

  • Add custom events (checkout, demo usage)
  • Create funnel visualization
  • Set up weekly email reports
  • Monitor bounce rate on /checkout

Phase 3: Advanced (Month 2)

  • A/B test pricing ($79 vs $99)
  • Test CTA copy ("Buy Now" vs "Get Started")
  • Analyze traffic sources (which channels convert?)
  • Set up Google Ads conversion tracking (if running ads)

Privacy & GDPR Compliance

If your audience is in EU:

  1. Add cookie consent banner (use a library like cookie-consent)
  2. Anonymize IPs (already enabled: anonymizeIP: true)
  3. Privacy policy — Disclose analytics usage
  4. Opt-out option — Allow users to disable tracking

Simple implementation:

// demo-docs-website/src/components/CookieConsent/index.js
import React, { useEffect, useState } from 'react';

export default function CookieConsent() {
const [show, setShow] = useState(false);

useEffect(() => {
const consent = localStorage.getItem('cookie_consent');
if (!consent) setShow(true);
}, []);

const accept = () => {
localStorage.setItem('cookie_consent', 'accepted');
setShow(false);
// Enable analytics
window.gtag('consent', 'update', {
analytics_storage: 'granted',
});
};

if (!show) return null;

return (
<div style={{ position: 'fixed', bottom: 0, left: 0, right: 0, background: '#333', color: '#fff', padding: 16, zIndex: 9999 }}>
<p>We use cookies to analyze site usage. <a href="/privacy" style={{ color: '#4a9eff' }}>Privacy Policy</a></p>
<button onClick={accept} style={{ padding: '8px 16px', background: '#4a9eff', color: '#fff', border: 'none', borderRadius: 4, cursor: 'pointer' }}>Accept</button>
</div>
);
}

Testing Analytics

Verify tracking works:

# 1. Install GA Debugger extension (Chrome)
https://chrome.google.com/webstore/detail/google-analytics-debugger

# 2. Visit your site
https://your-site.vercel.app

# 3. Open DevTools → Console
# Should see GA debug logs

# 4. Check GA4 Real-Time report
# Should see your visit within 30 seconds

Test checkout event:

  1. Go to /checkout
  2. Click "Buy Now"
  3. Check DevTools → Network → Filter: "collect"
  4. Look for event with en=begin_checkout

Expected Results

After 30 days with analytics:

You'll know:

  • ✅ How many people visit /pro vs /checkout
  • ✅ Conversion rate (visitors → buyers)
  • ✅ Which traffic sources convert best
  • ✅ Where users drop off in the funnel
  • ✅ ROI of marketing efforts

You can optimize:

  • 💰 Pricing (test $79 vs $99)
  • 📝 Copy (test different value props)
  • 🎨 Design (test button colors, layouts)
  • 🚀 Marketing (double down on what works)

Quick Start (5 Minutes)

# 1. Get GA4 tracking ID
Go to https://analytics.google.com → Create property → Copy ID

# 2. Update config
Edit demo-docs-website/docusaurus.config.js
Replace 'G-57MLE6HBT9' with your ID

# 3. Deploy
vercel --prod

# 4. Test
Visit your site → Check GA4 real-time reports

Done! You're now tracking conversions.


TL;DR

Current status: ✅ GA4 installed but using placeholder ID

Action required: Replace G-57MLE6HBT9 with your tracking ID

Time: 5 minutes

Impact: Critical for measuring success and optimizing revenue

Next steps:

  1. Create GA4 property (free)
  2. Update tracking ID in config
  3. Deploy
  4. Start tracking conversions!

See also: