revstrat/bloganalytics

Pulls Google Analytics data and provides queued jobs for updating data

0.7 2019-01-08 13:12 UTC

This package is auto-updated.

Last update: 2024-03-09 01:20:25 UTC


README

Pull data out of Google Analytics for pages and blog tags

Requirements

Documentation

The SilverStripe BlogAnalytics module uses a Google Service Account to interact with Google Analytics.

  1. Set up a service account here. You will receive a configuration such as this:
{
  "type": "service_account",
  "project_id": "YOUR GOOGLE API PROJET ID",
  "private_key_id": "YOUR PRIVATE KEY ID",
  "private_key": "YOUR PRIVATE KEY",
  "client_email": "EMAIL ADDRESS FOR THE SERVICE ACCOUNT",
  "client_id": "CLIENT ID",
  "auth_uri": "AUTH URI",
  "token_uri": "TOKEN URI",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "CERT URL"
}
  1. Add the email address for the account to Google Analytics
  2. Get a View ID for the Analytics view you wish to pull from
  3. base64 encode the configuration
  4. Add configuration to your environment:
GASERVICE="BASE64 ENCODED JSON CONFIGURATION FILE CONTENTS (to avoid escaping values in the private key)"
GAVIEW="VIEW ID"
GASTART="7daysago"
GAEND="today"
GAMINCUTOFF="100" # Don't track pages with fewer views than this
  1. Install with composer require revstrat\bloganalytics
  2. Run /dev/build?flush=all.
  3. Create a queued job of type RevStrat\BlogAnalytics\UpdateTrafficData and run it. The task will schedule itself on completion for 3 hours in the future

Template Usage

Examples:

TopTags, TopSiteTree, TopBlogPosts each return a list, with the target object itself under "Item", and the traffic count under "Traffic".

Each can take an argument to override the default result count limit.

<h3>Top Tags</h3>
<% loop TopTags(6) %>
    $Item.Title, $Traffic<br />
<% end_loop %>
<% loop TopSiteTree %>
  $Item.Title, $Traffic<br />
<% end_loop %>
<% loop TopBlogPosts %>
  $Item.Title, $Traffic<br />
<% end_loop %>