Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Happyr/GoogleAnalyticsBundle
The Google Analytics Bundle lets you send data (like event tracking) to Google.
https://github.com/Happyr/GoogleAnalyticsBundle
Last synced: 13 days ago
JSON representation
The Google Analytics Bundle lets you send data (like event tracking) to Google.
- Host: GitHub
- URL: https://github.com/Happyr/GoogleAnalyticsBundle
- Owner: Happyr
- Created: 2013-07-04T06:35:54.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-11-08T10:59:48.000Z (about 1 year ago)
- Last Synced: 2024-10-31T10:07:11.334Z (16 days ago)
- Language: PHP
- Homepage:
- Size: 103 KB
- Stars: 49
- Watchers: 5
- Forks: 15
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Google Analytics Bundle
=======================[![Latest Version](https://img.shields.io/github/release/Happyr/GoogleAnalyticsBundle.svg?style=flat-square)](https://github.com/Happyr/GoogleAnalyticsBundle/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/github/checks-status/Happyr/GoogleAnalyticsBundle/master?label=build&style=flat-square)](https://github.com/Happyr/GoogleAnalyticsBundle/actions?query=branch%3Amaster)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Happyr/GoogleAnalyticsBundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/Happyr/GoogleAnalyticsBundle)
[![Quality Score](https://img.shields.io/scrutinizer/g/Happyr/GoogleAnalyticsBundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/Happyr/GoogleAnalyticsBundle)
[![Total Downloads](https://img.shields.io/packagist/dt/happyr/google-analytics-bundle.svg?style=flat-square)](https://packagist.org/packages/happyr/google-analytics-bundle)GoogleAnalyticsBundle is a Symfony2 bundle that helps you to push data to Google Analytics.
It could be data like pageview, events etc. It is a bundle implementation of
the [Measurement Protocol][devguide]This is not a library to pull data from Google analytics. That feature is deprecated from the `classic-analytics` branch.
The master branch and version 3 and above will be supporting Google analytics universal.## Special feature
This bundle has a special feature. Say that you want to post data to Analytics. You want to post an event every time someone downloads a file. You may do that from the server like any other library. When looking at the reports you will find that you are missing the information about the actual user for the download event. You can not use a segment to find out which referal the user came from.
This bundle helps you with just that. Before we submit any data we look at the `_ga` cookie to find the user's clientId. So now you may use segments and advanced queries to analytics and you will get the expected result.
## Usage
Read the documentation of the [protocol][devguide].
``` php
//in some container aware class
$tracker = $this->get(Tracker::class);
$data=array(
'dh'=>'mydemo.com',
'dp'=>'/home',
'dt'=>'homepage',
);
$tracker->send($data, 'pageview');```
## Installation
Install with composer.
``` bash
composer require happyr/google-analytics-bundle
```### Step 2: Register the bundle
Register the bundle in the AppKernel.php
```php
Account > Property > View > View settings.``` yaml
# app/config/config.ymlhappyr_google_analytics:
// ...
tracking_id: UA-XXXX-Y
fetching:
client_service: 'google.client.tobias_gmail'
view_id: 0123456789
cache_service: 'cache.provider.my_memcached' # optinally a PSR6 cache service
cache_lifetime: 3600 # default
```You may then run the following code to get the page views for /example-page.
``` php
$fetcher = $this->get(AnalyticsDataFetcher::class);
$pv = $fetcher->getPageViews('/example-page');
```[devguide]: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
[siteAuth]: https://github.com/Happyr/GoogleSiteAuthenticatorBundle