shamaseen / laravel-analytics
Get your website traffic/conversion analytics natively from Laravel WITHOUT using Google analytic or any third party.
Requires
- illuminate/support: >6
- matomo/device-detector: ^4.3
- nesbot/carbon: ^2.53.0
This package is auto-updated.
Last update: 2025-02-17 06:34:33 UTC
README
Laravel analytics is an analytic tool to track conversions, weather you want to track visitors of your website or other conversions such us registration, subscription, or any type of action, then Laravel analytics is what you are looking for.
Laravel analytics will also record the user\guest device information, such as the device type, os, browser, version, language, city, country, continent, timezone for statistics.
NOTE: this package does NOT use Google Analytics, if you want Google analytics use spatie/laravel-analytics package instead.
installation
Run
composer install shamaseen/laravel-analytics
Publish the config file by running
php artisan vendor:publish --provider="Shamaseen\Analytics\ServiceProvider"
and at last run
php artisan migrate
to run the migration files.
Usage
Create
Create conversion:
Shamaseen\Analytics\Models\LaConversion::conversion($name,$weight = 100,$source = null, $force = false );
To create conversion for a model, use Shamaseen\Analytics\Traits\Conversionable
as a trait in the model you want, then:
yourModelInstance->la_conversions()->create([ 'name' => 'String: Required field', 'weight' => 'Int: Optional field', 'source' => 'String: Optional field', 'force' => 'Boolean: Optional field, set this to true to force the insertion ', ])
Statistics
To get statistics about the conversions create an instance of the Statistics class
$statistics = new \Shamaseen\Analytics\Repositories\Statistics($name, $start_at = null, $end_at = null)
or from yourModelInstance, like
yourModelInstance->la_statistics($name,$start_at = null, $end_at = null)
By default, all method will return data about the current month only, if you want to adjust the date, set the start at and the end at when instancing the Statistics class.
Now you can run methods like:
$statistics->sourcesCount()
$statistics->citiesCount()
$statistics->countriesCount()
$statistics->continentCount()
$statistics->timezoneCount()
$statistics->conversionsOverTime()
Extending the methods
You can always run your custom queries like you always do using the LaConversion
model, but remember, this is an open source project, so new methods to the statistics class is always welcomed to be added, just make a request :).
Statistics Data type
By default, statistics methods will return Laravel Collections, if you want to return arrays instead call:
$statistics->setResponse(\Shamaseen\Analytics\Repositories\Statistics::$ARRAY_RESPONSE)
License
This project is an open source project licensed under MIT.