- Notifications
You must be signed in to change notification settings - Fork32
📊 Laravel Google Analytics Measurement Protocol Package
License
irazasyed/laravel-gamp
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Laravel GAMP: Google Analytics Measurement Protocol Package for Laravel & Lumen.
Send data to Google Analytics from Laravel/Lumen. Supports all GA Measurement Protocol API methods.
$ composer require irazasyed/laravel-gamp
Openbootstrap/app.php
and register the service provider by adding:
$app->register(Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider::class);
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"
Open config fileconfig/gamp.php
and set thetracking_id
with your Google Analytics tracking / web property ID.Refer the config file for other default configuration settings.
This Package adds Laravel Support toGA 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 listedhere are available and will work seamlessly.
Send a Page view hit:
useIrazasyed\LaravelGAMP\Facades\GAMP;$gamp =GAMP::setClientId('123456' );$gamp->setDocumentPath('/page' );$gamp->sendPageview();
Send an Event:
useIrazasyed\LaravelGAMP\Facades\GAMP;$gamp =GAMP::setClientId('123456' );$gamp->setEventCategory('Blog Post')->setEventAction('Create')->setEventLabel('Using GAMP In Laravel')->sendEvent();
Open the config file for detailed comments for each option.
Set your Google Analytics Tracking / Web Property ID intracking_id
key[REQUIRED]
'tracking_id' =>'UA-XXXX-Y',
All other configuration options are optional, use as per your requirements.
To send data over SSL, setis_ssl
to true.
'is_ssl' => true,
To disable library in Staging/Dev env (Prevents the library from sending any hits to GA), setis_disabled
to true.
'is_disabled' => true,
To Anonymize IP, setanonymize_ip
to true.
'anonymize_ip' => true,
To Make Async Requests, setasync_requests
to true.
'async_requests' => true,
...
Refer the library'sdocumentation 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.
Any issues, pleasereport here
- Syed Irfaq R. - For Laravel and Lumen Bridge.
- THE ICONIC - For GA Measurement Protocol PHP Library.
- All Contributors
The MIT License (MIT). Please seeLicense File for more information.
About
📊 Laravel Google Analytics Measurement Protocol Package