• This repository has been archived on 16/Feb/2022
  • Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚠️ [ABANDONED] Rinvex Statistics is a lightweight, yet detailed package for tracking and recording user visits across your Laravel application. With only one simple query per request, important data is being stored, and later a cronjob crush numbers to extract meaningful stories from within the haystack.

Rinvex Statistics

⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️

👉 If you are interested to step on as the main maintainer of this package, please reach out to me!


Rinvex Statistics is a lightweight, yet detailed package for tracking and recording user visits across your Laravel application. With only one simple query per request, important data is being stored, and later a cronjob crush numbers to extract meaningful stories from within the haystack.

Unlike other tracking packages that seriously damage your project's performance (yes, I mean that package you know 😅), our package takes a different approach by just executing only one query at the end of each request after the response is being served to the user, through the terminate method of an automatically attached middleware, and then later on it uses the raw data previously inserted in the database to extract meaningfull numbers. This is done based on a random lottery request, or through a scheduled job (recommended) that could be queued to offload the heavy crunching work.

Rinvex Statistics tracks each -valid- request, meaning only requests that goes through routing pipeline, which also means that any wrong URL that results in NotFoundHttpException will not be tracked. If requested page has uncaught exceptions, it won't be tracked as well. It track user's logged in account (if any), session of all users and guests (if any), device (family, model, brand), platform (family, version), browser (agent, kind, family, version), path, route (action, middleware, parameters), host, protocol, ip address, language, status codes, and many more, and still we've plenty of awesome features planned for the future.

With such a huge collected data, the statistics_requests database table will noticeably increase in size specially if you've a lot of visits, that's why it's recommended to clean it periodically. Other important data will stay still in their respective tables, normalized and without any performance issues, so only this table need to be cleaned. By default that will be done automatically every month.

The default implementation of Rinvex Statistics comes with zero configuration out-of-the-box, which means it just works once installed. But it's recommended to change the defaults and disable the "Statistics Crunching Lottery" from config file, and replace it with a Scheduled Tasks for even better performance if you've large number of visits. See Usage for details.

Packagist Scrutinizer Code Quality Travis StyleCI License

Installation

  1. Install the package via composer:

    composer require rinvex/laravel-statistics
  2. Publish resources (migrations and config files):

    php artisan rinvex:publish:statistics
  3. Execute migrations via the following command:

    php artisan rinvex:migrate:statistics
  4. Done!

Usage

Well, this is the fun part! Rinvex Statistics has no usage instructions, because it just works! You install it and you are done! Seriously!!

Anyway, as a recommended performance tweak go ahead and do the following (optionally):

  1. Publish config file via the following command:

    php artisan rinvex:publish:statistics
    
  2. Disable the "Statistics Crunching Lottery" from config file.

  3. Follow the default Laravel documentation about Scheduled Tasks, then schedule both \Rinvex\Statistics\Jobs\CrunchStatistics and \Rinvex\Statistics\Jobs\CleanStatisticsRequests jobs at whatever intervals you see appropriate.

  4. Enjoy!

Note: Rinvex Statistics has a \Rinvex\Statistics\Http\Middleware\TrackStatistics middleware that attach itself automatically to the web middleware group, that's how it works out-of-the-box with zero configuration.

Data retrieval

You may need to build your own frontend interface to browse statistics, and for that you can utilize any of the included eloquent models as you normally do with Laravel Eloquent.

All eloquent models are self explainatory:

  • \Rinvex\Statistics\Models\Agent browser agent model
  • \Rinvex\Statistics\Models\Datum raw statistics data (to be crunched)
  • \Rinvex\Statistics\Models\Device user device model
  • \Rinvex\Statistics\Models\Path request path model
  • \Rinvex\Statistics\Models\Platform user platform model
  • \Rinvex\Statistics\Models\Request request data model (to be cleaned periodically)
  • \Rinvex\Statistics\Models\Route request route details model

All models are bound to the Service Container so you can swap easily from anywhere in your application. In addition to the default normal way of using these models explicitely, you can use their respective service names as in the following example:

// Find first browser agent (any of these methods are valid and equivalent)
app('rinvex.statistics.agent')->first();
new \Rinvex\Statistics\Models\Agent::first();
app(\Rinvex\Statistics\Contracts\AgentContract::class)->first();

Same for all other eloquent models.

Counts that matters

All agent, device, path, platform, route models have a count attribute, which gets updated automatically whenever a new request has been tracked.

This count attribute reflects number of hits. To make it clear let's explain through data samples:

Agents

id kind family version count name
1 desktop Chrome 63.0.3239 734 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36

This means there's 734 visit to our project through Chrome browser, version 63.0.3239, with agent (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36)

Devices

id family model brand count
1 iPhone iPhone Apple 83

This means there's 83 visits to our project through iPhone device.

Platforms

id family version count
1 Mac OS X 10.12.6 615

This means there's 615 visits to our project through Mac OS X operating system, with version 10.12.6.

Paths

id host locale path parameters count
1 test.homestead.local en en/adminarea/roles/admin {"role": "admin", "locale": "en"} 12

This means there's 12 visits to the admin dashboard roles management of the test.homestead.local host (in case you have multiple hosts or wildcard subdomains enabled on the same project, you can track all of them correctly here). The english interface was used, and the accessed route had two parameters, one for locale (english in this case), and updated role record (admin in this case).

This table could be used as a visit counter for all your pages. To retrieve and display page views you can use the following code for example:

$pageViews = app('rinvex.statistics.path')->where('path', request()->decodedPath())->first()->count;

And simply use the $pageViews variable anywhere in your views or controllers, or anywhere else. That way you have automatic visit counter for all your project's pages, very useful and performant, ready at your fingertips. You can add host contraint in case you have wildcard subdomains enabled.

Routes

id name path action middleware parameters count
1 adminarea.roles.edit {locale}/adminarea/roles/{role} App\Http\Controllers\Adminarea\RolesController@form ["web","nohttpcache","can:access-adminarea","auth","can:update-roles,roles"] {"role": "[a-z0-9-]+", "locale": "[a-z]{2}"} 41

This means there's 41 visits to the adminarea.roles.edit route, which has the {locale}/adminarea/roles/{role} raw path, and served through the App\Http\Controllers\Adminarea\RolesController@form controller action, and has the following middleware applied ["web","nohttpcache","can:access-adminarea","auth","can:update-roles,roles"], knowing the route accepts two parameters with the following regex requirements {"role": "[a-z0-9-]+", "locale": "[a-z]{2}"}.

As you can see, this statistics_routes table beside the statistics_paths table are both complimentary, and could be used together to track which paths and routs are being accessed, how many times, and what controller actions serve it, and what parameters are required, with the actual parameter replacements used to access it. Think of routes as your raw links blueprint map, and of paths as the executed and actually used links by users.

Geoips

id client_ip latitude longitude country_code client_ips is_from_trusted_proxy division_code postal_code timezone city count
1 127.0.0.0 41.31 -72.92 US NULL 0 CT 06510 America/New_York New Haven 57

This means there's 57 visits to the project from IP address 127.0.0.0 with the latitude, longitude and timezone mentioned above coming from New Haven city, Connecticut state.

Requests

id route_id agent_id device_id platform_id path_id geoip_id user_id user_type session_id method status_code protocol_version referer language is_no_cache wants_json is_secure is_json is_ajax is_pjax created_at
1 123 123 123 123 123 123 123 user MU22QcrzDIdj0gY27yJmUPJHNFy9Hlqvkel1KBZ1 GET POST 200 HTTP/1.1 https://google.com en_US 0 0 1 0 0 0

This is the most comprehensive table that records every single request made to the project, with access details as seen in the sample above. Through session_id, user_id and user_type you can track guests (logged out) and users (logged in) and extract unique visits/visitors with the criteria you see appropriate for you.

Notes:

  • As a final note, this package is a data hord, and it doesn't actually do much of the math that could be done on such a valuable gathered data, so it's up to your imagination to utilize it however you see fits your goals. Implementation details is up to you.
  • We didn't explain the statistics_data table since it's used for temporary raw data storage until it's being crunched and processed by the package, so you should NOT care or mess with that table. It's used internally by the package and has no real end-user usage.
  • The \Rinvex\Statistics\Models\Request model has relationships to all related data such as agent, device, path, platform, and route. So once you grab a request instance you can access any of it's relationships as you normaly do with Eloquent Relationships like so: $statisticsRequest->agent->version or $statisticsRequest->platform->family.

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to [email protected]. All security vulnerabilities will be promptly impressioned.

About Rinvex

Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License

This software is released under The MIT License (MIT).

(c) 2016-2022 Rinvex LLC, Some rights reserved.

More Repositories

1

countries

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.
PHP
1,640
star
2

laravel-subscriptions

⚠️ [ABANDONED] Rinvex Subscribable is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP
726
star
3

laravel-repositories

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
PHP
667
star
4

laravel-bookings

⚠️ [ABANDONED] Rinvex Bookable is a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP
458
star
5

laravel-categories

Rinvex Categorizable is a polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.
PHP
454
star
6

laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
PHP
434
star
7

laravel-addresses

⚠️ [ABANDONED] Rinvex Addressable is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.
PHP
240
star
8

laravel-auth

A powerful authentication, authorization and verification package built on top of Laravel. It provides developers with Role Based Access Control, Two-Factor Authentication, Social Authentication, and much more, compatible Laravel’s standard API and fully featured out of the box.
PHP
132
star
9

laravel-cacheable

⚠️ [ABANDONED] Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
PHP
111
star
10

cortex-classic

Rinvex Cortex is a solid foundation for enterprise solutions, that provides a flexible and extensible architecture for building multi-lingual, multi-tenant applications with content management, themeable views, application modules and much more.
PHP
94
star
11

laravel-tenants-classic

Rinvex Tenantable is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.
PHP
82
star
12

laravel-support

Rinvex common support helpers, contracts, and traits required by various Rinvex packages. Validator functionality, and basic controller included out-of-the-box.
PHP
73
star
13

universities

Rinvex University is a simple and lightweight package for retrieving university details with flexibility. A whole bunch of data including name, country, state, email, website, telephone, address, and much more attributes for the 17k+ known universities worldwide at your fingertips.
PHP
57
star
14

obsolete-larapulse

⚠️ [ABANDONED] This project is abandoned and no longer maintained. The author suggests following https://twitter.com/LaravelLog on twitter for @laravelphp framework specific changes instead.
PHP
41
star
15

laravel-widgets

⚠️ [ABANDONED] Rinvex Widgets is a powerful and easy to use widget system, that combines the both power of code logic and the flexibility of template views. You can create asynchronous widgets, reloadable widgets, and use the console generator to auto generate your widgets, all out of the box.
PHP
40
star
16

laravel-pages

Rinvex Pages is an integral part of your content management system (CMS), it affords an easy, yet powerful way to create and manage pages with full control over their URLs, active status, titles, content, and other attributes.
PHP
38
star
17

authy

Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
PHP
36
star
18

laravel-authy

Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
PHP
35
star
19

laravel-contacts

⚠️ [ABANDONED] Rinvex Contacts is a polymorphic Laravel package, for contact management system. You can add contacts to any eloquent model with ease.
PHP
30
star
20

laravel-menus

Rinvex Menus is a simple menu builder package for Laravel, that supports hierarchical structure, ordering, and styling with full flexibility using presenters for easy styling and custom structure of menu rendering.
PHP
30
star
21

languages

Rinvex Language is a simple and lightweight package for retrieving language details with flexibility. A whole bunch of data including name, native, iso codes, language family, language script, language cultures, and other attributes for the 180+ known languages worldwide at your fingertips.
PHP
29
star
22

laravel-tags

Rinvex Taggable is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.
PHP
27
star
23

laravel-forms

⚠️ [ABANDONED] Rinvex Forms is a dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease.
PHP
15
star
24

punnet

Rinvex Punnet is opinionated, lightweight, yet powerful, and performant light speed docker environment for PHP applications.
Shell
14
star
25

laravel-testimonials

⚠️ [ABANDONED] Rinvex Testimonials is a Laravel package for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype!
PHP
13
star
26

cortex-auth-classic

Cortex Fort is a frontend layer for the powerful authentication, authorization and verification package rinvex/fort on top of Laravel. It has all required controllers, views, routes, and other required assets to run a fully functional user management system with complete dashboard out of the box.
PHP
12
star
27

cortex-tenants-classic

Cortex Tenantable is a frontend layer for the contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others
Blade
12
star
28

laravel-composer

Rinvex Composer is an intuitive package that utilizes Composer Plugin API to support additional actions during installation, such as installing packages outside of the default vendor library and running custom scripts during install, update, and uninstall processes.
PHP
11
star
29

cortex-attributes-classic

Cortex Attributable is a frontend layer for the robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
PHP
9
star
30

cortex-bookings-classic

Cortex Bookings is a front layer of a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP
8
star
31

cortex-categories-classic

Cortex Categorizable is a frontend layer for the polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.
PHP
8
star
32

cortex-foundation-classic

The core foundation of Rinvex Cortex modular application architecture.
PHP
7
star
33

cortex-tags-classic

Cortex Taggable is a frontend layer for the polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.
PHP
6
star
34

cortex-statistics-classic

Cortex Statistics is a frontend layer for lightweight, yet detailed package for tracking and recording user visits across your Laravel application. With only one simple query per request, important data is being stored, and later a cronjob crush numbers to extract meaningful stories from within the haystack.
PHP
6
star
35

cloudinit

Shell
5
star
36

cortex-pages-classic

Cortex Pages is a frontend layer for an integral part of your Laravel content management system (CMS), it affords an easy, yet powerful way to create and manage pages with full control over their URLs, active status, titles, content, and other attributes.
PHP
5
star
37

laravel-oauth

Rinvex OAuth is an OAuth2 server and API authentication package that is simple and enjoyable to use.
PHP
4
star
38

cortex-oauth-classic

Cortex OAuth is a frontend layer for the OAuth server Laravel package, for API management.
PHP
2
star
39

cortex-contacts-classic

Cortex Contacts is a frontend layer for the polymorphic contact management system. You can add contacts to any eloquent model with ease.
PHP
2
star
40

renamed-country

⚠️ This package is renamed and now maintained at https://github.com/rinvex/countries, author suggests using the new package instead.
PHP
2
star
41

cortex-settings-tenantable-classic

Cortex Settings Tenantable is a new module for rinvex/cortex applications.
PHP
1
star
42

cortex-installer

⚠️ [ABANDONED] Rinvex Cortex Installer is a command line tool that depends on composer to install the Cortex projects seamlessly.
PHP
1
star
43

cortex-console-classic

Cortex Console is a set of powerful tools for administrators and system support staff, to maintain the project through a web console.
PHP
1
star
44

cortex-forms-classic

Cortex Forms is a frontend layer for dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease.
PHP
1
star
45

cortex-testimonials-classic

Cortex Testimonials is a frontend layer for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype!
PHP
1
star