A package to keep track of your pages & understand your audience

Overview

Laravisit Logo

The Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

A clean way to track your pages & understand your user's behavior

Installation

You can install the package via composer:

composer require coderflexx/laravisit

You can publish the config file with:

php artisan vendor:publish --provider="Coderflex\\Laravisit\\LaravisitServiceProvider"

then, run database migration

php artisan migrate

This is the contents of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | User Namespace
    |--------------------------------------------------------------------------
    |
    | This value informs Laravist which namespace you will be 
    | selecting to get the user model instance
    | If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used 
    | by default.
    |
    */
    'user_namespace' => "\Coderflex\Laravisit\Models\User",
];

Usage

Use HasVisits Trait

The first thing you need to do is, to use HasVisits trait, and implement CanVisit interface.

namespace App\Models\Post;

use Coderflex\Laravisit\Concerns\CanVisit;
use Coderflex\Laravisit\Concerns\HasVisits;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements CanVisit
{
    ...
    use HasFactory;
    use HasVisits;
    ...
}

After this step, you are ready to go, and when you need to track a page, do it like this:

$post->visit();

You can chain methods to the visit method. Here is a list of the available methods:

METHOD SYNTAX DESCRIPTION EXAMPLE
withIp() string $ip = null Set an Ip address (default request()->ip()) $post->visit()->withIp()
withData() array $data Set custom data $post->visit()->withData(['region' => 'USA'])
withUser() Model $user = null Set a user model (default auth()->user()) $user->visit()->withUser()

By default, you will have unique visits each day using dailyInterval() method. Meaning, when the users access the page multiple times in the day time frame, you will see just one record related to them.

If you want to log users access to page with different timeframes, here are a bunch of useful methods:

METHOD SYNTAX DESCRIPTION EXAMPLE
hourlyInterval() void Log visits each hour $post->visit()->hourlyIntervals()->withIp();
dailylyInterval() void Log visits each daily $post->visit()->dailylyIntervals()->withIp();
weeklyInterval() void Log visits each week $post->visit()->weeklyIntervals()->withIp();
monthlyInterval() void Log visits each month $post->visit()->monthlyIntervals()->withIp();
yearlyInterval() void Log visits each year $post->visit()->yearlyIntervals()->withIp();
customInterval() mixed $interval Log visits within a custom interval $post->visit()->customInterval( now()->subYear() )->withIp();

Get The Records With Popular Time Frames

After the visits get logged, you can retrieve the data by the following method:

METHOD SYNTAX DESCRIPTION EXAMPLE
withTotalVisitCount() void get total visit count Post::withTotalVisitCount()->first()->visit_count_total
popularAllTime() void get popular visits all time Post::popularAllTime()->get()
popularToday() void get popular visits in the current day Post::popularToday()->get()
popularLastDays() int $days get popular visits last given days Post::popularLastDays(10)->get()
popularThisWeek() void get popular visits this week Post::popularThisWeek()->get()
popularLastWeek() void get popular visits last week Post::popularLastWeek()->get()
popularThisMonth() void get popular visits this month Post::popularThisMonth()->get()
popularLastMonth() void get popular visits last month Post::popularLastMonth()->get()
popularThisYear() void get popular visits this year Post::popularThisYear()->get()
popularLastYear() void get popular visits last year Post::popularLastYear()->get()
popularBetween() Carbon $from, Carbon $to get popular visits between custom two dates Post::popularBetween(Carbon::createFromDate(2019, 1, 9), Carbon::createFromDat(2022, 1, 3))->get();

Visit Presenter

This package is coming with helpful decorate model properties, and it uses Laravel Presenter package under the hood.

METHOD SYNTAX DESCRIPTION EXAMPLE
ip() void Get the associated IP from the model instance $post->visits->first()->present()->ip
user() void Get the associated User from the model instance $post->visits->first()->present()->user->name

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Inspiration

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(v1.2.3)
  • v1.2.3(Dec 18, 2022)

    What's Changed

    • GitHub Actions Badges by @ousid in https://github.com/coderflexx/laravisit/pull/24
    • Bump ramsey/composer-install from 1 to 2 by @dependabot in https://github.com/coderflexx/laravisit/pull/23

    Full Changelog: https://github.com/coderflexx/laravisit/compare/v1.2.2...v1.2.3

    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Nov 5, 2022)

    What's Changed

    • Bump dependabot/fetch-metadata from 1.3.3 to 1.3.4 by @dependabot in https://github.com/coderflexx/laravisit/pull/19
    • Update README by @parastooam in https://github.com/coderflexx/laravisit/pull/21
    • Bump actions/checkout from 2 to 3.1.0 by @dependabot in https://github.com/coderflexx/laravisit/pull/20

    New Contributors

    • @parastooam made their first contribution in https://github.com/coderflexx/laravisit/pull/21

    Full Changelog: https://github.com/coderflexx/laravisit/compare/v1.2.1...v1.2.2

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Aug 22, 2022)

    What's Changed

    • Larastan Fix Errors by @ousid in https://github.com/coderflexx/laravisit/pull/17
    • Enhancements by @ousid in https://github.com/coderflexx/laravisit/pull/16

    Full Changelog: https://github.com/coderflexx/laravisit/compare/v1.2.0...v1.2.1

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Aug 21, 2022)

    What's Changed

    • Enhancement by @ousid in https://github.com/coderflexx/laravisit/pull/13
    • FEAT: Added with session function by @juliangarcess in https://github.com/coderflexx/laravisit/pull/15

    Full Changelog: https://github.com/coderflexx/laravisit/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 14, 2022)

    What's Changed

    • FEAT: Added CrawlerDetect by @juliangarcess in https://github.com/coderflexx/laravisit/pull/12

    New Contributors

    • @juliangarcess made their first contribution in https://github.com/coderflexx/laravisit/pull/12

    Full Changelog: https://github.com/coderflexx/laravisit/compare/v1.0.3...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Feb 15, 2022)

  • v1.0.2(Feb 14, 2022)

  • v1.0.1(Feb 14, 2022)

  • v1.0.0(Feb 14, 2022)

Owner
Coderflex
Full Stack web development Company
Coderflex
Laravel Seeable - Keep track of the date and time a user was last seen.

Laravel Seeable This package makes it easy to keep track of the date and time a user was last seen. Installation Install this package. composer requir

Zep Fietje 29 Dec 26, 2022
Laravel Lumen service provider for Understand.io

The service provider is deprecated - it does not support error grouping. Laravel Lumen service provider for Understand.io You may also be interested i

null 6 May 30, 2019
This package allows you to easily track your laravel jobs!

Trackable Jobs For Laravel This package allows you to track your laravel jobs! Using this package, you can easily persist the output and the status of

Mateus Junges 220 Dec 25, 2022
A Laravel package to help track user onboarding steps.

Onboard A Laravel package to help track user onboarding steps. Installation: Install the package via composer composer require calebporzio/onboard Reg

Caleb Porzio 440 Dec 17, 2022
Ensure your Laravel applications keep a normal pulse

Ensure your Laravel applications keep a normal rhythm Laravel Defibrillator helps you ensure that aspects of your application that should be running a

Michael Dyrynda 148 Dec 20, 2022
Laravel plugin to track your users logins and alert when a suspicious login occurs

Laravel Suspicious Logins Detect suspicious logins for standard Laravel authentication (base Laravel, Jetstream, etc) and notify a list of administrat

Advent Development 74 May 1, 2022
Prerender Laravel pages using Clusteer and this nice package.

Laravel Clusteer Prerender Prerender Laravel pages using Clusteer and this nice package. ?? Supporting If you are using one or more Renoki Co. open-so

Renoki Co. 4 Aug 10, 2022
Thunder is an advanced Laravel tool to track user consumption using Cashier's Metered Billing for Stripe. ⚡

⚡ Thunder Thunder is an advanced Laravel tool to track user consumption using Cashier's Metered Billing for Stripe. ⚡ ?? Supporting If you are using o

Renoki Co. 10 Nov 21, 2022
🕵🏻‍♂️  The easiest way to respect the "do not track" header in Laravel

trackable The easiest way to respect the "do not track" header in Laravel Installation composer require s360digital/trackable API Trackable will expos

s360 2 Oct 7, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Orchestra Platform 1.9k Dec 29, 2022
This package provides extended support for our spatie/enum package in Laravel.

Laravel support for spatie/enum This package provides extended support for our spatie/enum package in Laravel. Installation You can install the packag

Spatie 264 Dec 23, 2022
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

Tinashe Musonza 931 Dec 24, 2022
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) ?? ?? ?? This package helps you to know a lot of information about the current user by his ip address ?? ?? ?? This package h

Abdullah Karam 4 Dec 8, 2022
🥳🔐 This package is a Laravel package that checks if an email address is a spammer

This package is a Laravel package that checks if an email address is a spammer. It verifies your signups and form submissions to confirm that they are legitimate.

Endurance, the Martian 15 Dec 19, 2022
Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.

Laravel Eloquent Scope as Select Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes an

Protone Media 75 Dec 7, 2022
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

Malik Alleyne-Jones 17 Aug 25, 2022
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

UB Labs 12 Jan 17, 2022
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 17, 2022