PHPackages                             happyr/google-analytics-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. happyr/google-analytics-bundle

ActiveSymfony-bundle

happyr/google-analytics-bundle
==============================

The Google Analytics Bundle lets you send data (like event tracking) to Google.

5.0.2(5y ago)49247.2k↓34.5%16[5 issues](https://github.com/Happyr/GoogleAnalyticsBundle/issues)[1 PRs](https://github.com/Happyr/GoogleAnalyticsBundle/pulls)MITPHPPHP ^7.1

Since Jul 4Pushed 2y ago4 watchersCompare

[ Source](https://github.com/Happyr/GoogleAnalyticsBundle)[ Packagist](https://packagist.org/packages/happyr/google-analytics-bundle)[ Docs](http://developer.happyr.com/symfony2-bundles/google-analytics-bundle)[ RSS](/packages/happyr-google-analytics-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (13)Versions (26)Used By (0)

Google Analytics Bundle
=======================

[](#google-analytics-bundle)

[![Latest Version](https://camo.githubusercontent.com/86f52e128ca2eb5ac02a78d47b011637ff0d8bb7db45e1c9375a8adda0daf895/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4861707079722f476f6f676c65416e616c797469637342756e646c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Happyr/GoogleAnalyticsBundle/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/11a2efc3f80d173e2c50c01d2b9908925fb554fb7b72821358a2a136a863e5f9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f4861707079722f476f6f676c65416e616c797469637342756e646c652f6d61737465723f6c6162656c3d6275696c64267374796c653d666c61742d737175617265)](https://github.com/Happyr/GoogleAnalyticsBundle/actions?query=branch%3Amaster)[![Code Coverage](https://camo.githubusercontent.com/bd7f8062a1eba0d935c0b5acc8be716c9a974de1d9c9a1e9bb6139a3ea846ef6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f4861707079722f476f6f676c65416e616c797469637342756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Happyr/GoogleAnalyticsBundle)[![Quality Score](https://camo.githubusercontent.com/308f11144250dd27e8df58888bcae9a4d5075761e763a54e9ef800c9f4e78562/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4861707079722f476f6f676c65416e616c797469637342756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Happyr/GoogleAnalyticsBundle)[![Total Downloads](https://camo.githubusercontent.com/e6b9772adfdb4c627ac72d50f7a3193c174684b98921f85dbba524f9c322c988/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6861707079722f676f6f676c652d616e616c79746963732d62756e646c652e7376673f7374796c653d666c61742d737175617265)](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](https://developers.google.com/analytics/devguides/collection/protocol/v1/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
---------------

[](#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
-----

[](#usage)

Read the documentation of the [protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide).

```
//in some container aware class
$tracker = $this->get(Tracker::class);
$data=array(
    'dh'=>'mydemo.com',
    'dp'=>'/home',
    'dt'=>'homepage',
);
$tracker->send($data, 'pageview');
```

Installation
------------

[](#installation)

Install with composer.

```
composer require happyr/google-analytics-bundle
```

### Step 2: Register the bundle

[](#step-2-register-the-bundle)

Register the bundle in the AppKernel.php

```
