Fetches data from Google analytics.
Create Your Credentials
i) Create a Service Account
Go to the Credentials page in the Google APIs console.
If you don't have an existing Google Cloud project, click "Create" to create a new project. Otherwise, use the dropdown in the upper left corner to select the existing project that you'd like to use.
Select "Service Account key" from the "Create credentials" dropdown.
Fill out the form for creating a service account key:
- Service account dropdown: Select "New Service Account".
- Service account name: Give your service account a name.
- Role: Select "Service Account User" ("Service Accounts" > "Service Account User").
- Service account ID: This field will automatically be pre-filled, but you can change this if you would like.
- Key type: Select JSON key.
This should start a download of the credentials file
Configure Google Analytics
i) Add service account to Google Analytics
The service account that you just created needs to be added as a user to your Google analytics account.
- Login to your Google Analytics account.
- Add a new user. (Admin > User Management > + > Add New Users)
- Email Address The email address of the service account you created. It should look something like this: email@example.com.
- Permissions: Select "Read & Analyze."
Note: A service account can only be associated with one Google Analytics account at a time. Thus, if you want to use predictive fetching on multiple sites, you'll need to create a separate service account for each.
ii) Enable the Google Analytics Reporting API
You can enable this here.
Set up credentials
To use the credentials in your project, copy it your project,
and make sure to add it or its folder to gitignore.
You can also opt to take
private_key from the credentials file, and add them to env.
Get your view ID
To find your view ID, go to Google Analytics. Click the accounts dropdown (it's located in the upper lefthand corner of the screen, right next to the Google Analytics logo). The dialog that opens will have three columns: Analytics Accounts, Properties & Apps, & Views. The far right column ("Views") will contain the View ID for your site.
You can opt to save this in an .env file if you do not want to share this information.
npm i guess-ga
guess-parser you can aggregate the route information and map it to your application's parametrized routes:
For more details visit https://github.com/guess-js/guess.