Google Analytics Measurement Protocol Package for Symfony

Overview

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:


// 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

Comments
  • isAsyncRequest is false despite

    isAsyncRequest is false despite "four_labs_gamp.async_requests: true" is set in confing.yml

    Hi,

    During XDEBUG session I've noticed that param isAsyncRequest is set to false in TheIconic\Tracking\GoogleAnalytics\Analytics instance. I have to set $analytics->setAsyncRequest(true), to set the param to true.

    My config.yml:

    four_labs_gamp:
        protocol_version: 1
        tracking_id: "%google.analytics.tracking.id%"
        use_ssl: true
        anonymize_ip: false
        async_requests: true
        sandbox: %google.analytics.is.sandbox%
    

    Also I noticed that async_requests prop is defaulted to true in FourLabs\GampBundle\DependencyInjection\Configuration::getConfigTreeBuilder() and I tried to remove is from my config, but the isAsyncRequest remained false. I think it must be something wrong with the setter.

    opened by kestux 2
  • sending EventGA using GampBundle

    sending EventGA using GampBundle

    Hi

    Is it possible to send google analitics request for EventGa just to log website entry to statistics? Code below does not work:

    $this->get('gamp.analytics')
    ->setEventCategory('test')
    ->setEventAction('test')
    ->setEventLabel('test')
    ->sendEvent()
    

    Best Regards

    opened by Venzon 2
  • fix root node deprecation in symfony/config >= 4.2

    fix root node deprecation in symfony/config >= 4.2

    Add a backward compatible fix for the deprecation warning "A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0." (discussed in https://symfony.com/blog/new-in-symfony-4-2-important-deprecations#deprecated-tree-builders-without-root-nodes)

    This is a fix for issue #23

    opened by roverwolf 1
  • Problem with sending custom events

    Problem with sending custom events

    $this->get('gamp.analytics')
                ->setEventCategory('authorization')
                ->setEventAction('Authorization')
               ->setDocumentLocationUrl('/')
                ->sendEvent();
    

    this is a dump of the request

    {
    hitParsingResult: [
    {
    valid: true,
    parserMessage: [
    {
    messageType: "INFO",
    description: "IP Address from this hit was anonymized to 46.30.167.0.",
    messageCode: "VALUE_MODIFIED"
    }
    ],
    hit: "/debug/collect?v=1&tid=UA-109724385-2&aip=0&uip=127.0.0.1&ua=Mozilla%2F5.0%20%28X11%3B%20Linux%20x86_64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F70.0.3538.110%20Safari%2F537.36&cid=103528305.1546594228&ec=authorization&ea=Authorization&dl=%2F&t=event?_anon_uip=127.0.0.0"
    }
    ],
    parserMessage: [
    {
    messageType: "INFO",
    description: "Found 1 hit in the request."
    }
    ]
    }
    

    but nothing appear in dashboard

    opened by Roman9961 1
  • Symfony4 compatibility

    Symfony4 compatibility

    Hi @fourlabsldn

    Thanks to the work in pull request #16 of @emmanuelballery the bundle was nearly compatible with Symfony4. Some required fixes would be added with this pull request,

    Cheers Felix

    opened by n3r0-ch 1
  • Allow AnalyticsFactory to be public/shared and injected in other services

    Allow AnalyticsFactory to be public/shared and injected in other services

    Hi!

    I updated the AnalyticsFactory to be able to inject it in my services/create multiple analytics without requiring the entire container and calling $container->get('gamp.analytics') each time. This way, I can simply create multiple Analytics like this :

    use FourLabs\GampBundle\Service\AnalyticsFactory;
    
    class Stats
    {
        /** @var AnalyticsFactory */
        private $analyticsFactory;
    
        public function __construct(AnalyticsFactory $analyticsFactory)
        {
            $this->analyticsFactory = $analyticsFactory;
        }
    
        public function doSomething()
        {
            $analytics1 = $this->analyticsFactory->createAnalytics();
            // ...
            $analytics2 = $this->analyticsFactory->createAnalytics();
            // ...
        }
    }
    

    Could you take a look and tell me what you think.

    Thanks!

    opened by emmanuelballery 1
  • createAnalytics method in factory throws InvalidArgumentException when no user-agent set

    createAnalytics method in factory throws InvalidArgumentException when no user-agent set

    Injecting this service into another service causes the createAnalytics() method to be called, which accesses the request stack to get the User-Agent header. In the case this is not set (which often happens with requests from bots or 3rd party API callbacks) an exception is thrown. Since this happens when the services are instantiated, it's hard to handle gracefully.

    Passing an empty string to the setUserAgentOverride() method does not throw an exception, only a null value does. Since the user-agent isn't required by the GAMP API anyway, it seems this method should not be called in the constructor or gracefully handle a null value.

    opened by JunkMyFunk 1
  • fix cookie ga management + set compatibility with guzzle 5

    fix cookie ga management + set compatibility with guzzle 5

    Hello, I create a fork of your bundle and I manage to handle properly the cookie issue #1 and the take into account Guzzle 5 dependencies #2

    You can find in my fork repository 2 tags (1.1.0 and 2.0.0):

    • 1.1.0 is for "theiconic/php-ga-measurement-protocol": "^1.1" with Guzzle 5
    • 2.0.0 is for "theiconic/php-ga-measurement-protocol": "^2.0" with Guzzle 6

    Thank you in advance for the merge!

    If you have any question don't hesitate!

    opened by Nightbr 1
  • Generate two tags for php-ga-measurement-protocol ^2.0 and ^1.1

    Generate two tags for php-ga-measurement-protocol ^2.0 and ^1.1

    Hello,

    I have a dependencies issue with GampBundle. In my project I already have dependencies which requires guzzlehttp/guzzle 5.x. But here we are, GampBundle (great bundle!) require "theiconic/php-ga-measurement-protocol": "^2.0"which require guzzlehttp/guzzle 6

    It would be really nice if you could made two versions of GampBundle:

    • One which require "theiconic/php-ga-measurement-protocol": "^1.1" for Guzzle 5
    • and another which require "theiconic/php-ga-measurement-protocol": "^2.0" for Guzzle 6

    Doc here

    I am really stuck and I prefer use the main repository of the project whereas using a fork. I think it can be usefull for everyone!

    Thanks in advance.

    Regards,

    Titouan

    opened by Nightbr 1
  • Deprecation warning: A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0

    Deprecation warning: A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0

    Per https://symfony.com/blog/new-in-symfony-4-2-important-deprecations#deprecated-tree-builders-without-root-nodes, the way to generate a TreeBuilder and get the root node has changed.

    opened by roverwolf 0
  • Symfony 6 Support

    Symfony 6 Support

    Hey, friends. Looks like somebody has posted a PR with a reasonable 'update' for Symfony 6 support, since all the underlying code is compliant with PHP 8.

    Any chance you could merge this in and issue a new release to make migration a bit easier for folks using this library still?

    Thanks!

    opened by ruttencutter 0
  •  InvalidArgumentException The attribute 'shared' is not allowed

    InvalidArgumentException The attribute 'shared' is not allowed

    Hi

    I just installed GampBundle 2.0 in a Symfony 2.7 project.

    I'm getting this exception:

    image

    Removing the shared attribute in fourlabs/gamp-bundle/Resources/config/services.xml on line 21 fixes the problem. However, I don't know if it may have other consequences:

    image

    opened by mauricoder 1
  • setClientId() not specified receives a null value

    setClientId() not specified receives a null value

    Hi,

    I noticed I had a lot of log entries with the following message : Uncaught PHP Exception InvalidArgumentException: "For Analytics object, you must specify a value to be set for setClientId"

    Also, after looking for a while in my code, I found that there was an error in the AnalyticsFactory class on line 25. ->setClientId($request->cookies->get('_ga', null))

    Based on the Google Analytics Measurement Protocol library for PHP the **setClientId _method need a value and cannot receive a _null.

    Am I right and does anybody also had this problem ? Thanks for your advice.

    opened by yanict 6
Releases(2.5.0)
Owner
Four Labs
Projects developed by Four Labs, a London software delivery team (now closed).
Four Labs
A measurement field for ProcessWire

Fieldtype Measurement This fieldtype allows a measurement unit to be stored with a corresponding measurement value ('magnitude'). The relevant details

Mark Evens 2 Aug 6, 2022
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

MagePal :: Magento Extensions 303 Oct 7, 2022
PHP Protobuf - Google's Protocol Buffers for PHP

This repository is no longer maintained Since Google's official Protocol Buffers supports PHP language, it's unjustifiable to maintain this project. P

Allegro Tech 912 Dec 16, 2022
Server side analytics for Magento 2

Server Side Analytics for Magento 2 This extension aims to solve the problem of discrepancies between Magento revenue reports and the revenue reports

elgentos ecommerce solutions 46 Dec 9, 2022
run user analytics within your system and track user data inside your database.

WP Local Analytics plugin. run user analytics within your system and track user data inside your database. Installing Go to the plugin page from the W

Gary 5 Dec 21, 2022
Columnar analytics for PHP - a pure PHP library to read and write simple columnar files in a performant way.

Columnar Analytics (in pure PHP) On GitHub: https://github.com/envoymediagroup/columna About the project What does it do? This library allows you to w

Envoy Media Group 2 Sep 26, 2022
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol

Opengraph Test with Atoum cd Opengraph/ curl -s https://getcomposer.org/installer | php php composer.phar install --dev ./vendor/atoum/atoum/bin/atoum

Axel Etcheverry 89 Dec 27, 2022
MajorDoMo is an open-source DIY smarthome automation platform aimed to be used in multi-protocol and multi-services environment.

MajorDoMo (Major Domestic Module) is an open-source DIY smarthome automation platform aimed to be used in multi-protocol and multi-services environment. It is based on web-technologies stack and ready to be delivered to any modern device. It is very flexible in configuration with OOP paradigm used to set up automation rules and scripts. This platform can be installed on almost any personal computer running Windows or Linux OS.

Sergei Jeihala 369 Dec 30, 2022
A PHP implementation of the Unleash protocol aka Feature Flags in GitLab.

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab. This implementation conforms to the official Unleash standards and implement

Dominik Chrástecký 2 Aug 18, 2021
An implementation of the Minecraft: Bedrock Edition protocol in PHP

BedrockProtocol An implementation of the Minecraft: Bedrock Edition protocol in PHP This library implements all of the packets in the Minecraft: Bedro

PMMP 94 Jan 6, 2023
Spotweb is a decentralized usenet community based on the Spotnet protocol.

Spotweb is a decentralized usenet community based on the Spotnet protocol. Spotweb requires an operational webserver with PHP5.6 installed, it

Spotweb 433 Jan 1, 2023
Spotweb is a decentralized usenet community based on the Spotnet protocol.

Spotweb Spotweb is a decentralized usenet community based on the Spotnet protocol. Spotweb requires an operational webserver with PHP5.6 installed, it

[sCRiPTz-TEAM] 2 Nov 29, 2021
> Create e-wallet, send money, withdraw and check balance all via USSD protocol

Mobile Money USSD solution Create e-wallet, send money, withdraw and check balance all via USSD protocol Create e-wallet Step 1 Step 2 Step 3 Step 4 S

Emmanuel HAKORIMANA 1 Nov 3, 2021
Tars is a high-performance RPC framework based on name service and Tars protocol, also integrated administration platform, and implemented hosting-service via flexible schedule.

TARS - A Linux Foundation Project TARS Foundation Official Website TARS Project Official Website WeChat Group: TARS01 WeChat Offical Account: TarsClou

THE TARS FOUNDATION PROJECTS 9.6k Jan 1, 2023
TiDB is an open source distributed HTAP database compatible with the MySQL protocol

What is TiDB? TiDB ("Ti" stands for Titanium) is an open-source NewSQL database that supports Hybrid Transactional and Analytical Processing (HTAP) wo

PingCAP 33.1k Jan 9, 2023
Starless Sky is a network protocol for secure identities, providing the use of assymetric identities, public information, end-to-end messaging and smart contracts

Descentralized network protocol providing smart identity over an secure layer. What is the Starless Sky Protocol? Starless Sky is a network protocol f

Starless Sky Protocol 3 Jun 19, 2022
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Felix Becker 1.1k Jan 4, 2023
This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol

log2ck This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol. If you can write regular rules, other st

Hisune 9 Aug 15, 2022
Simple Symfony API-Platform Template which you can use to start to develop with symfony and api-platform

symfony-api-platform-skeleton Simple Template for Symfony API You can fork it and change the git remote to your Repo git remote set-url <your-git-remo

null 1 Jan 23, 2022