Registry / analytics / guess-ga

guess-ga

JSON →
library0.4.20jsnpmunverified

Fetches structured pageview data from Google Analytics, primarily used with guess.js for predictive prefetching. Current version 0.4.20 releases infrequently. Key differentiator: it pulls GA data for ML-driven route prediction, not just reporting. Requires service account credentials and GA view ID. Deprecated in favor of guess-ga in the guess-js organization.

npm install guess-ga
INSTALL
IMPORT
SIG · GUESS-GA
G
guess-ga
analyticsjavascriptv0.4.20
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetch
import { fetch } from 'guess-ga'
import fetch from 'guess-ga'
fetch is a named export, not default. Use named import syntax.
fetch
const { fetch } = require('guess-ga')
const fetch = require('guess-ga'); const fetchFn = fetch.fetch
CommonJS destructure works correctly; avoid accessing .fetch on the module object.
fetch
import { fetch as guessFetch } from 'guess-ga'
import * as guess from 'guess-ga'; const fetch = guess.default
No default export exists; avoid misleading default import.

Demonstrates fetching Google Analytics pageview data with JWT authentication and route list.

import { fetch } from 'guess-ga'; import { JWT } from 'google-auth-library'; const credentials = require('./credentials.json'); const auth = new JWT( credentials.client_email, null, credentials.private_key, ['https://www.googleapis.com/auth/analytics.readonly'] ); const viewId = '123456789'; fetch({ auth, viewId, period: { startDate: new Date('2023-01-01'), endDate: new Date() }, routes: ['/', '/about', '/contact'] }).then(data => { console.log(JSON.stringify(data, null, 2)); }).catch(console.error);
Debug
Known issues
deprecatedguess-ga is effectively deprecated in the guess-js ecosystem; consider using guess-ga from @guess-js/ga or migrating to newer alternatives.
fix
Migrate to @guess-js/ga or use the official Google Analytics Data API directly.
affects: >=0.1.0
breakingBreaking: In version 0.4.0, the 'fetch' function signature changed: 'period' now requires Date objects (not strings), and 'routes' must be an array of strings.
fix
Ensure period.startDate and period.endDate are Date instances and routes is an array of route paths.
affects: >=0.4.0
gotchaService account credentials must have 'Read & Analyze' permissions in Google Analytics; otherwise fetch returns empty data or errors.
fix
Add the service account email as a user in GA with 'Read & Analyze' permissions.
affects: >=0.1.0
gotchaThe Google Analytics Reporting API must be enabled for the project; otherwise authentication succeeds but requests fail with 403.
fix
Enable the 'Google Analytics Reporting API' in the Google Cloud Console for the project.
affects: >=0.1.0
gotchaA service account can only be associated with one Google Analytics account at a time; for multiple properties, create separate service accounts.
fix
Create a new service account for each Google Analytics account and download separate credentials.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Authentication failed: missing client_email or private_key
Credentials object passed to JWT is missing required fields.
fix
Ensure credentials.json contains 'client_email' and 'private_key' properties.
Error: Google Analytics API returned error: User does not have sufficient permissions
Service account lacks 'Read & Analyze' access in Google Analytics.
fix
Add the service account email as a user in GA with 'Read & Analyze' permissions.
TypeError: period.startDate.getTime is not a function
period.startDate or period.endDate is not a Date object (e.g., string).
fix
Convert startDate and endDate to Date instances before passing to fetch.
Error: The route list is empty
The 'routes' parameter is an empty array or undefined.
fix
Provide at least one route string in the routes array.
Upgrade
Version history
0.4.20latest on npm
Audit
Dependencies
google-auth-libraryrequiredRequired for JWT authentication to access Google Analytics API
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
guess-ga — npm install guess-ga · libregistry