Permalink
Browse files

Merge branch 'master' of github.com:antimattr/GoogleBundle

  • Loading branch information...
2 parents 635c590 + 8cadb31 commit 8de3f84822acde05b45832294955ece2bf92f05c @matthewfitz matthewfitz committed May 18, 2012
View
@@ -21,12 +21,19 @@ class Analytics
private $pageViewsWithBaseUrl = true;
private $trackers;
private $whitelist;
+ private $api_key;
+ private $client_id;
+ private $table_id;
- public function __construct(ContainerInterface $container, array $trackers = array(), array $whitelist = array())
+ public function __construct(ContainerInterface $container,
+ array $trackers = array(), array $whitelist = array(), array $dashboard = array())
{
$this->container = $container;
$this->trackers = $trackers;
$this->whitelist = $whitelist;
+ $this->api_key = isset($dashboard['api_key']) ? $dashboard['api_key'] : '';
+ $this->client_id = isset($dashboard['client_id']) ? $dashboard['client_id'] : '';
+ $this->table_id = isset($dashboard['table_id']) ? $dashboard['table_id'] : '';
}
public function excludeBaseUrl()
@@ -427,4 +434,30 @@ private function getTransactionFromSession()
{
return $this->container->get('session')->get(self::TRANSACTION_KEY);
}
+
+ /**
+ *
+ * @return string
+ */
+ public function getApiKey()
+ {
+ return $this->api_key;
+ }
+
+ /**
+ *
+ * @return string
+ */
+ public function getClientId()
+ {
+ return $this->client_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getTableId()
+ {
+ return $this->table_id;
+ }
}
@@ -65,6 +65,9 @@ private function analyticsLoad(array $configs, ContainerBuilder $container)
if (isset($config['trackers'])) {
$container->setParameter('google.analytics.trackers', $config['trackers']);
}
+ if (isset($config['dashboard'])) {
+ $container->setParameter('google.analytics.dashboard', $config['dashboard']);
+ }
if (isset($config['whitelist'])) {
$container->setParameter('google.analytics.whitelist', $config['whitelist']);
}
@@ -110,6 +110,21 @@ public function getTrackers(array $trackers = array())
{
return $this->analytics->getTrackers($trackers);
}
+
+ public function getApiKey()
+ {
+ return $this->analytics->getApiKey();
+ }
+
+ public function getClientId()
+ {
+ return $this->analytics->getClientId();
+ }
+
+ public function getTableId()
+ {
+ return $this->analytics->getTableId();
+ }
public function isTransactionValid()
{
@@ -15,6 +15,7 @@
<argument type="service" id="service_container" />
<argument>%google.analytics.trackers%</argument>
<argument>%google.analytics.whitelist%</argument>
+ <argument>%google.analytics.dashboard%</argument>
</service>
<service id="templating.helper.google_analytics" class="AntiMattr\GoogleBundle\Helper\AnalyticsHelper">
@@ -0,0 +1,88 @@
+Google Dashboard API
+====================
+
+The bundle adds support for the [google dashboard library](http://googledevelopers.blogspot.com/2012/05/new-google-analytics-easy-dashboard.html).
+
+## Usage
+
+
+### Configuration
+
+Add your google api credentials in your configuration (see the above link how to set it up):
+
+``` yml
+google:
+ analytics:
+ # .... other settings
+ dashboard:
+ api_key: your-api-key
+ client_id: your-client-id
+ table_id: your-table-id
+```
+
+### Initializtation
+
+In your dashboard, simply include the `dashboard.html.twig` template with an optional `initCallback` parameter:
+
+``` jinja
+ {% include "GoogleBundle:Analytics:dashboard.html.twig" with { 'initCallback' : 'myDashCallback' } %}
+```
+
+The `myDashCallback` is a name of a javascript function which is being called after the google dashboard library has been initialized.
+
+
+### Authorization
+
+The dashboard library needs a button to initialize the google authorization, this defaults to the id `authorize-button`:
+
+``` html
+<button id="authorize-button" style="visibility:hidden">Authorize Google Analytics</button>
+```
+
+The id of the element can be configured by passing a `authorizeButton` parameter to the dashboard twig template.
+
+### Drawing charts
+
+Once the user is authorized at google, you can start drawing your analytics charts in your templates:
+
+``` html
+
+<div class="gadash-container">
+ <h3>Visits</h3>
+ <div id='dataOverTimeConfig'></div>
+<div>
+
+<script type="text/javascript">
+
+function adminInit() {
+
+ // Create new Chart.
+ var dataOverTime = new gadash.Chart({
+ 'last-n-days': 30,
+ 'chartOptions': {
+ width: 700
+ },
+ 'divContainer': 'dataOverTimeConfig',
+ 'type': 'LineChart',
+ 'query': {
+ 'dimensions': 'ga:date',
+ 'sort': 'ga:date',
+ 'metrics': 'ga:visitors, ga:visits, ga:pageviews',
+ 'ids' : gadash.tableId
+ },
+ 'chartOptions': {
+ height: 300,
+ legend: {position: 'bottom'},
+ hAxis: {title:'Date'},
+ curveType: 'function'
+ }
+ }).render();
+}
+
+</script>
+```
+
+Note that you need to pass the `gadash.tableId` in each chart, otherwise you'll get an api error.
+
+
+
Oops, something went wrong.

0 comments on commit 8de3f84

Please sign in to comment.