Coder Social home page Coder Social logo

gampbundle's Introduction

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

gampbundle's People

Contributors

foaly-nr1 avatar ivan1986 avatar kuraobi avatar nightbr avatar roverwolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gampbundle's Issues

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

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.

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

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

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

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.

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.

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.