Display website visitors information from Google Analytics API
To make this work, you’ll need a google API credential, link it to google analytics and find your website viewID.
- Open the Service accounts page and create a project named wtfutil.
- Navigation menu > IAM & admin > Service accounts
- Click add Create Service Account, enter a name (wtfutil) for the service account.
- The Service account permissions (optional) section that follows is not required. Click Continue.
- On the Grant users access to this service account screen, scroll down to the Create key section. Click add Create key.
- In the side panel that appears, select the format for your key: JSON.
- Click Create. Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key.
- Copy this json to indicated filepath in wtfutil googleanalytics module Configuration.
- Enable the Google Analytics APIS and Services (Navigation menu > APIS and Services > +Enable APIS and Services > Google Analytics Reporting API > Enable)
The newly created service account will have an email address that looks similar to:
Use this email address to add a user to the Google analytics view you want to access via the API (admin > user management > add users). Only Read & Analyze permissions are needed. Get the website viewID and put it in the config file.
Real Time Data
This module also supports displaying the number of visitors on each view live via the Google Analytics Real Time Reporting API Beta. In order to use this feature, you must sign up for the beta and wait for your whitelist application to be approved (which takes less than 24 hours). Once you’re approved, all you need to do is set
enableRealtime: true in the module settings.
googleanalytics: enabled: true enableRealtime: true months: 5 position: top: 0 left: 3 width: 2 height: 1 refreshInterval: 400 secretFile: "~/.config/wtf/google_analytics/client_secret.json" viewIds: tessellation: "00000000" dylanbartels.com: "111111111"
||Optional Whether or not this module is executed and if its data displayed onscreen. Default:
||When set to
||The amount of months being displayed with website session data.||Any positive integer.|
||Defines where in the grid this module’s widget will be displayed.|
||Optional How often, in seconds, this module will update its data. Default:
||Any positive integer.|
||Your Google client secret JSON file.||A string representing a file path to the JSON secret file.|
||Website(s) who will be displayed in the module, label does not have to corresponding to the actual url. Value must be the google analytics viewID of the website.||A string representing the viewID.|