Import GA4 history
Bring the daily numbers of a Google Analytics 4 property into a trackr portal, so a site keeps its history after switching.
A site that switches from Google Analytics 4 keeps its history: the portal’s trackr command
fetches daily numbers from the GA4 Data API and stores them as daily totals of the site. The
dashboard counts them like its own days and says how many days in the range come from GA4.
Access to the property
The import signs in with a Google Cloud service account that may read the property:
- In a Google Cloud project, enable the Google Analytics Data API and create a service account with a JSON key.
- In GA4 under Admin → Property access management, add the service account’s email as Viewer.
- Note the numeric property ID (Admin → Property details).
The key is used for the import only; trackr does not store it.
Run the import
The command needs the portal’s Postgres in DATABASE_URL, as the Docker image has it:
docker compose exec -T trackr trackr import ga4 --site <site-id> --property 123456789 \
--from 2024-01-01 --to 2026-10-31 --key - < service-account.json
Without Docker, run node apps/dashboard/dist-node/cli.js import ga4 … after
pnpm --filter @trackr/dashboard build:node. The site ID is in the admin area.
--todefaults to yesterday; today is never imported, because GA4’s numbers of the current day are incomplete.- Days for which trackr has data of its own are skipped: trackr’s numbers always win, and the two sources never add up. The command lists the skipped days.
- Running it again replaces the imported days of the range, so a failed or partial run can simply be repeated.
- A portal on Cloudflare D1 cannot be imported into with this command yet.
What is imported
| trackr | from GA4 |
|---|---|
| Users, sessions, views | totalUsers, sessions, screenPageViews per day |
| Bounces | sessions minus engagedSessions |
| Engagement time | userEngagementDuration per session; per view for a page |
| Pages | pagePathPlusQueryString |
| Referrers | host of pageReferrer; none is direct |
| Countries | countryId |
| Devices, browsers, OS | deviceCategory, browser, operatingSystem |
| Campaigns | sessionManualSource, sessionManualMedium, sessionManualCampaignName |
| Channels | sessionDefaultChannelGroup, as GA4 computed it |
| Events | eventName and eventCount, without GA4’s own events (page_view, session_start, first_visit, user_engagement) |
Where the numbers differ
- Approximations: GA4 withholds small numbers when thresholding applies and groups rare values as “(other)” in large reports. The command prints a note when a report is affected.
- Users: GA4 counts users with its cookie. Where several GA4 values become one trackr value (referrer URLs of one host, unknown device types), their users are added up.
- Days: GA4 days follow the property’s time zone, trackr’s are UTC days.
- Universal Analytics: Google deleted its data in 2024; only GA4 properties can be imported.
What the GA4 terms mean in trackr: trackr and GA4 metrics.