Google Analytics Setup
Getting credentials JSON
Head over to Google APIโs site using your google account and select or create a project.
Set API's the project. Go to the API Library and search for "Google Analytics Data API".
Choose enable to enable the API.
If you dont have an Analytics account before, fill in the form like image below.
- Go to Analytics site. Fill account name
- Fill in property name, reporting time zone and currency.
- Check anything that your business is about.
- Check anything that your business objective.
- Choose data collection to get Analytics Tracking ID
Go to Google API and select a project that you want from the header.
Go to Credential and create a new credential. Click Create Credentials and select Service account.
- Fill in the form with service account name and account ID that you like. After that, click Create button and click Done.
To obtain service account credential JSON, press edit on the new created service account.
Select KEYS menu from the tab. Click Add Key and select Create new key. After that, select JSON and click Create button.
After you create the key, it'll automatically download the key.
Place your .json key to storage directory like below.
๐ฆ Your Project
โฃ ๐ storage
โ โฃ ๐ app
โ โ โฃ ๐ analytics // If the directory doesn't exists, just create it
โ โ โ โ ๐ service-account-credentials.json // Filename must be the same
Granting permissions to your Analytics property
- Go to Google Analytics page.
- Select Admin menu from sidebar. Select Property access management
- New window will appear, after that click Add users.
- Open the credential that we get before, search for
client_email
. Copy the email. - Paste it in the Email addresses field and select permission that you want. You must check Viewer permissions. After that, press Done button.
Getting the ID that you need.
Account ID
Select Admin menu from sidebar and select Account Details.
There you have it.
Property ID / View ID
- Select Admin menu from sidebar and select Property Details. There you have it
Tracking ID
- Go to Analytics Home menu. There you have it
Web Property ID
Open Google Analytics page.
Look at the page URL. The web property ID start with p. Usually it has 9 character. For example: https://analytics.google.com/analytics/web/#/p299999997/reports/intelligenthome
The web property ID for that account is 299999997.