GithubHelp home page GithubHelp logo

riseofthetigers / laravel-gamp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from digideskio/laravel-gamp

0.0 2.0 0.0 49 KB

Laravel 4/5 & Lumen 5 Google Analytics Measurement Protocol Package

Home Page: http://git.io/xti2

License: MIT License

PHP 100.00%

laravel-gamp's Introduction

Laravel-GAMP Package

Laravel & Lumen Package Latest Version on Packagist Software License SensioLabsInsight Total Downloads

Laravel GAMP: Google Analytics Measurement Protocol Package for Laravel 5 & Lumen 5. Send data to Google Analytics from Laravel/Lumen. Supports all GA Measurement Protocol API methods.

Laravel GAMP

Quick start

If you're on Laravel 4.2 or on 5.0 with PHP 5.4 & above, Please use 0.5 branch. Otherwise, Just follow the below instructions.

Supported Laravel/Lumen Versions: 5.1 & 5.2

Installation

Step 1: Install Through Composer

You can either add the package directly by firing this command

$ composer require irazasyed/laravel-gamp

Or add in the require key of composer.json file manually

"irazasyed/laravel-gamp": "^1.0"

And Run the Composer update command

$ composer update

Step 2: Add the Service Provider

Laravel

Open config/app.php and, to your "providers" array at the bottom, add:

Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider::class
Lumen

Open bootstrap/app.php and add register the service provider by adding:

$app->register(Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider::class);

Step 3: Add Facade (Optional) (Laravel Only)

Optionally add an alias to make it easier to use the library. Open config/app.php and, to your "aliases" array at the bottom, add:

'GAMP'  => Irazasyed\LaravelGAMP\Facades\GAMP::class

Step 4: Publish Config (Laravel Only)

Open your terminal window and fire the following command to publish config file to your config directory:

$ php artisan vendor:publish --provider="Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider"

OR

$ php artisan vendor:publish

The former command publishes config file for just this package and the latter publishes vendor files for other packages too. Depending on what you want to do, you can use any (Doesn't really matter).

Usage

Open config file config/gamp.php and set the tracking_id with your Google Analytics tracking / web property ID. Refer the config file for other default configuration settings.

This Package adds Laravel Support to GA Measurement Protocol PHP Library by THE ICONIC. It's simply a wrapper around the library with default config for easier usage with Laravel. So all the methods listed here are available and will work seamlessly.

Example Usage

Send a Page view hit:

use Irazasyed\LaravelGAMP\Facades\GAMP;

$gamp = GAMP::setClientId( '123456' );
$gamp->setDocumentPath( '/page' );
$gamp->sendPageview();

Send an Event:

use Irazasyed\LaravelGAMP\Facades\GAMP;

$gamp = GAMP::setClientId( '123456' );
$gamp->setEventCategory('Blog Post')
->setEventAction('Create')
->setEventLabel('Using GAMP In Laravel')
->sendEvent();

Config Overview

Open the config file for detailed comments for each option.

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

'tracking_id' => 'UA-XXXX-Y',

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

To send data over SSL, set is_ssl to true.

'is_ssl' => true,

To Anonymize IP, set anonymize_ip to true.

'anonymize_ip' => true,

To Make Async Requests, set async_requests to true.

'async_requests'  => true,

...

Refer the library's documentation for other remaining methods and examples, they all work.

Note: You don't have to use the protocol version, tracking id, anonymize ip and async request (non-blocking) methods from the original library as they're automatically set in Service Provider when the package is initialized based on the config file. As long as you update the config file with correct settings, it should work just fine.

Additional information

Any issues, please report here

Credits

License

MIT © Syed Irfaq R.

laravel-gamp's People

Contributors

irazasyed avatar james2doyle avatar

Watchers

James Cloos avatar  avatar

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.