Migrate from Google Analytics

Step-by-step guide to migrate from Google Analytics (GA4) to JustAnalytics for privacy-first web analytics.

Overview#

JustAnalytics provides a complete, privacy-first replacement for Google Analytics 4 (GA4). Unlike GA4, JustAnalytics does not use cookies, does not share data with advertising networks, and is fully GDPR/CCPA compliant without a consent banner.

Use the JustAnalytics CLI to find and replace GA4 code in your project:

npx @justanalyticsapp/cli migrate from-ga --site-id YOUR_SITE_ID

This scans for gtag.js snippets, react-ga4 imports, and dataLayer.push calls, then replaces them with JustAnalytics equivalents.

For a dry run:

npx @justanalyticsapp/cli migrate from-ga --dry-run

Manual Migration#

Step 1: Remove the GA4 Script#

Before (Google Analytics):

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

After (JustAnalytics):

<script defer src="https://justanalytics.tech/tracker.js" data-site-id="YOUR_SITE_ID"></script>

That single script tag handles page views, sessions, referrer tracking, UTM parameters, scroll depth, and more — all automatically.

Step 2: Remove React GA Package (if using)#

npm uninstall react-ga4

No React wrapper package is needed. The JustAnalytics tracker script works with any framework.

Step 3: Replace Custom Events#

Before (GA4):

// gtag event
gtag('event', 'purchase', {
  currency: 'USD',
  value: 49.99,
  items: [{ item_id: 'SKU_123', item_name: 'Widget' }],
});

// react-ga4
import ReactGA from 'react-ga4';
ReactGA.event({
  category: 'Ecommerce',
  action: 'Purchase',
  value: 49.99,
});

// dataLayer
window.dataLayer.push({
  event: 'purchase',
  ecommerce: { value: 49.99 },
});

After (JustAnalytics):

// Option 1: JavaScript API
window.__ja?.trackEvent('purchase', {
  currency: 'USD',
  value: 49.99,
  item_id: 'SKU_123',
});

// Option 2: Data attribute (no JavaScript needed)
<button data-ja-event="purchase" data-ja-value="49.99">
  Buy Now
</button>

Step 4: Set Up Conversion Goals#

GA4 uses "conversions" (formerly "goals"). In JustAnalytics, you set these up in the dashboard:

  1. Go to Settings > Conversions
  2. Click Add Conversion Goal
  3. Define the trigger (e.g., custom event name purchase, or URL match /thank-you)
  4. Set an optional revenue value

Step 5: Concept Mapping#

| GA4 Concept | JustAnalytics Equivalent | Notes | |---|---|---| | gtag('config', 'G-XXX') | Automatic page tracking | JA tracker.js handles this automatically | | gtag('event', name, params) | window.__ja?.trackEvent(name, params) | Custom events via SDK or data attributes | | gtag('set', { user_id }) | window.__ja?.setUser({ id }) | Set user properties | | Measurement ID (G-XXX) | Site ID (data-site-id) | Site ID on the tracking script tag | | page_view | Automatic | JA tracks page views automatically | | user_engagement | Automatic | JA tracks engagement via scroll depth and time on page | | scroll | Automatic | JA tracks scroll depth automatically | | click (enhanced measurement) | data-ja-event attribute | Add data attribute for click tracking | | purchase | Conversion goal | Set up in JA dashboard | | Enhanced conversions | Conversion goals | Configure in Settings > Conversions | | Google Tag Manager | Not needed | JA uses a single lightweight script | | Consent mode | Not needed | JA is cookieless and GDPR-compliant by default |

Step 6: Update Tag Manager (if applicable)#

If you use Google Tag Manager (GTM), you can either:

  1. Replace GTM entirely — Just add the JA tracker script directly
  2. Add JA alongside GTM — If you need GTM for other tags, add the JA script in addition

We recommend option 1 for simplicity and performance.

Framework-Specific Instructions#

Next.js#

Before (GA4 with Next.js):

// app/layout.tsx
import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <Script src="https://www.googletagmanager.com/gtag/js?id=G-XXX" />
        <Script id="gtag-init">
          {`window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
          gtag('config', 'G-XXX');`}
        </Script>
      </head>
      <body>{children}</body>
    </html>
  );
}

After (JustAnalytics with Next.js):

// app/layout.tsx
import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <Script
          defer
          src="https://justanalytics.tech/tracker.js"
          data-site-id="YOUR_SITE_ID"
        />
      </head>
      <body>{children}</body>
    </html>
  );
}

React (Create React App / Vite)#

Replace the script tag in public/index.html or index.html:

<script defer src="https://justanalytics.tech/tracker.js" data-site-id="YOUR_SITE_ID"></script>

Remove any react-ga4 or react-ga imports from your components.

Verify Migration#

After migration, verify everything is working:

npx @justanalyticsapp/cli doctor

Then visit your site and check the JustAnalytics dashboard for incoming data.

Feature Comparison#

| Feature | Google Analytics 4 | JustAnalytics | |---|---|---| | Page views | Yes | Yes | | Sessions | Yes | Yes | | Bounce rate | Yes | Yes (engagement-based) | | Custom events | Yes | Yes | | Conversion tracking | Yes | Yes | | Real-time dashboard | Yes (24h delay for reports) | Yes (true real-time) | | Traffic sources / UTM | Yes | Yes | | Geographic data | Yes | Yes | | Device / browser data | Yes | Yes | | Scroll depth | Yes (enhanced measurement) | Yes (automatic) | | Error tracking | No | Yes | | Session replay | No | Yes | | Web Vitals | No | Yes | | Server-side tracing | No | Yes | | Log aggregation | No | Yes | | Cookies required | Yes | No | | GDPR consent banner | Required | Not needed | | Data shared with Google | Yes | No | | Data ownership | Google's servers | Your database | | Script size | ~45 KB | ~3 KB | | Pricing | Free (with data sampling) | $49/month (no sampling) |

Key Advantages#

  1. No cookies — JustAnalytics uses cookieless tracking. No consent banners needed.
  2. True real-time — Data appears on your dashboard in seconds, not hours.
  3. Lightweight — The tracker script is ~3KB vs GA4's ~45KB, improving your page load speed.
  4. Full data ownership — Your data stays in your database, not Google's.
  5. No data sampling — GA4's free tier samples data at high volumes. JA does not.
  6. All-in-one — Analytics, error tracking, session replay, and server-side observability in one tool.