Developed with love by KnpLabs Hire us for your project!
47

GampBundle

by fourlabsldn

Google Analytics Measurement Protocol bundle for Symfony

GAMP Bundle

Google Analytics Measurement Protocol Package for Symfony. Supports all GA Measurement Protocol API methods.

Build Status
StyleCI
Total Downloads
License
SensioLabsInsight

Installation

Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest version of this bundle:

$ composer require fourlabs/gamp-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Compatibility with Guzzle 5 and 6

If you are using PHP 5.5 or above and Guzzle 6 then:

{
    "require": {
        "fourlabs/gamp-bundle": "^2.0"
    }
}

Or if you are using PHP 5.4 or above and Guzzle 5 then:

{
    "require": {
        "fourlabs/gamp-bundle": "^1.1"
    }
}

Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FourLabs\GampBundle\FourLabsGampBundle(),
    );
}

Usage

This bundle exposes the service gamp.analytics. It is a non shared service, i.e. each time you retrieve the service you'll get a new instance.

Example
$this->get('gamp.analytics')
    ->setTransactionId('7778922')
    ->setAffiliation('THE ICONIC')
    ->setRevenue(250.0)
    ->setTax(25.0)
    ->setShipping(15.0)
    ->setCouponCode('MY_COUPON')
    ->setProductActionToPurchase()
    ->setEventCategory('Checkout')
    ->setEventAction('Purchase')
    ->sendEvent()
;

Refer to the library's documentation for other remaining methods and examples, they all work. This library 100% supports all GAMP features.

Note: You don't have to use the protocol version, tracking id, anonymize ip and async request (non-blocking) methods as they're automatically set in based on your config file.

Configuration

Example of configuration in app/config.yml:

four_labs_gamp:
    protocol_version: 1
    tracking_id: UA-XXXXXXX-X
    use_ssl: true
    anonymize_ip: false
    async_requests: true
    sandbox: true

Set your Google Analytics Tracking / Web Property ID in tracking_id key [REQUIRED]

See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid

tracking_id: UA-XXXX-Y

All other configuration options are optional, use as per your requirements.

The Protocol version. The current value is '1'. Default: 1

See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v

protocol_version: 1

To send data over SSL, set use_ssl to true. Default: true

See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid

use_ssl: true

To Anonymize IP, set anonymize_ip to true. Default: false

See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip

anonymize_ip: true

To Make Async Requests, set async_requests to true. Default: true

async_requests: true

When sandbox mode is enabled, no hits are actually sent to GA. In this case the library returns a AnalyticsResponseInterface object that with empty values. Default: false

sandbox: true

Credits

This package is a wrapper around the GA Measurement Protocol PHP Library. Thanks to the guys @ THE ICONIC who developed the library!

License

MIT

The MIT License (MIT)

Copyright (c) 2015 Four Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

four_labs_gamp:
protocol_version: 1
tracking_id: ~ # Required
use_ssl: true
anonymize_ip: false
async_requests: true
sandbox: false
  • support Symfony 5 (#27)
    By foaly-nr1, 11 months ago
  • Test against Symfony 4.2 (#25)
    By web-flow, 1 year ago
  • fix root node deprecation in symfony/config > 4.1 (#24)
    By foaly-nr1, 1 year ago
  • Test Symfony 4.1 and PHP 7.2 on Travis (#19)
    By web-flow, 2 years ago
  • Symfony4 compatibility (#18)
    By foaly-nr1, 2 years ago
  • Test 3.0 and 3.1 separately (#15)
    By web-flow, 3 years ago
  • Update README
    By foaly-nr1, 3 years ago
  • Test against both Symfony 2 and 3
    By foaly-nr1, 3 years ago
  • Configure travis
    By foaly-nr1, 3 years ago
  • Add AnalyticsFactoryTest class
    By foaly-nr1, 3 years ago
  • Fix typo
    By foaly-nr1, 3 years ago
  • Don't share the service gamp.analytics
    By foaly-nr1, 3 years ago
  • add enabled option - new in 2.6.0 (#12)
    By foaly-nr1, 3 years ago
  • Merge branch 'master' of https://github.com/fourlabsldn/GampBundle
    By foaly-nr1, 3 years ago
  • Upgrade library
    By foaly-nr1, 3 years ago
  • Merge pull request #11 from fourlabsldn/analysis-z4bOnG
    By web-flow, 3 years ago
  • Apply fixes from StyleCI
    By StyleCIBot, 3 years ago
  • Set debug mode according to env var
    By foaly-nr1, 3 years ago
  • Resolves #9. Credits to @DeonKuhn
    By foaly-nr1, 4 years ago
  • Upgrade library
    By foaly-nr1, 4 years ago
  • It's not just Symfony2
    By foaly-nr1, 4 years ago
  • Merge pull request #8 from fourlabsldn/analysis-XWogxN
    By web-flow, 4 years ago
  • Applied fixes from StyleCI
    By StyleCIBot, 4 years ago
  • Removing super global following 60a8920
    By foaly-nr1, 4 years ago
  • Resolves #4. Credits @FredoVelcro
    By foaly-nr1, 4 years ago
  • SensioLabsInsight recco
    By foaly-nr1, 4 years ago
  • Merge branch 'master' of https://github.com/fourlabsldn/GampBundle
    By foaly-nr1, 4 years ago
  • Add StyleCI badge
    By foaly-nr1, 4 years ago
  • Merge pull request #7 from fourlabsldn/analysis-XZogjR
    By web-flow, 4 years ago
  • Applied fixes from StyleCI
    By StyleCIBot, 4 years ago