How to setup your Google Analytics Service Account
In order for Posterno to display your Google's Analytics stats to your site's listings owners, you need to configure a special account that allows Posterno to read your data.
A service account is a special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs.
1. Enable the API
To get started using Analytics Reporting API, you need to first use the setup tool, which guides you through creating a project in the Google API Console, enabling the API, and creating credentials.
- Open the Service accounts page. If prompted, select a project.
- Click add Create Service Account, enter a name and description for the service account. You can use the default service account ID, or choose a different, unique one. When done click Create.
- 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 is required.
- Click Create. Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key.
- Click Close on the Private key saved to your computer dialog, then click Done to return to the table of your service accounts.
Add service account to the Google Analytics account
The newly created service account will have an email address that looks similar to:
2. Add the email address
It's recommended that you add the new user to the "All Web Site Data" view.
3. Add your credentials to Posterno
Now that you've created the service account and added the proper permissions, you need to provide the credentials to Posterno. There are 2 ways to provide the credentials to Posterno, it's recommended that you follow the "secure way".
Adding credentials: the easy way
The easiest way to add your credentials is to copy and paste the content of the .json file previously generated into the connection settings of Posterno. Open the .json file with a text editor and copy it's content. Next, login into your WordPress website and navigate to Settings → Posterno → Analytics and paste the content of the .json file into the setting called "Google Service account authentication json".
Adding credentials: the secure way
The safest way to store your credentials, requires you to copy it to your WordPress site’s server. For better security, we recommend defining the path to your access keys in your wp-config.php file.
define( 'PNO_ANALYTICS_ACCOUNT_PATH', '/path/to/key/file.json' );
Make sure to replace the “/path/to/key/file.json” string in the above example with the full path to the file on the server, it must be an absolute file path and must be accessible by the web server process that PHP is executed under. For security, do not store the file within the site’s own directory hierarchy where it could be downloaded by anyone.
4. Test the connection
Now that the keys have been generated and configured, it's time to test the connection to the Google's API. Login into your WordPress website and navigate to Settings → Posterno → Analytics and press the "Test connection" button. You'll see a message telling you the status of the connection, whether it was successful or not.
5. Add your View ID number to Posterno
In order for Posterno to understand where to grab it's data from, it needs a view ID number from your Google Analytics account. Login into Google Analytics and click on the "All accounts" tab into the top left corner. A window will show up, displaying all your analytics properties and views. Copy the number below the name of the view you wish to use from the "View" column. Paste the ID number into your Posterno's analytics options into the "Google Analytics View ID" setting.
6. Enable the data you wish to track
If you've carefully followed the instructions and the connection test was succesful, you can now enable the stats you wish to display into the fronted dashboard of your directory. To do so login into your WordPress website and navigate to Settings → Posterno → Analytics and enable the stats required from the "Stats to display" setting.