PHPackages                             alifahmmed/metrics-tracker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alifahmmed/metrics-tracker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alifahmmed/metrics-tracker
==========================

A Laravel helper package for store impression, click of a post with filter and ctr.

1.0.7(1y ago)024MITPHPPHP &gt;=8.1

Since Apr 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/s-m-alif-ahmmed/metrics-tracker)[ Packagist](https://packagist.org/packages/alifahmmed/metrics-tracker)[ Docs](https://github.com/s-m-alif-ahmmed/metrics-tracker)[ RSS](/packages/alifahmmed-metrics-tracker/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (8)Used By (0)

📊 MetricsTracker
================

[](#-metricstracker)

A Laravel package to **track impressions, clicks, and CTR** (Click-Through Rate) for any model like pages, posts, banners, or other content. Inspired by platforms like Fiverr and Upwork.

---

✨ Features
----------

[](#-features)

- ✅ Track impressions (when content is viewed)
- ✅ Track clicks (when user interacts)
- ✅ Automatically generates CTR (Click-Through Rate)
- ✅ Supports polymorphic relationships
- ✅ Artisan command to clean old records

---

📦 Installation
--------------

[](#-installation)

```
composer require alifahmmed/metrics-tracker
```

Then publish the migration:

```
php artisan vendor:publish --tag=public
php artisan migrate
```

🔧 Setup

🎮 1. How to Use in Controller You can easily integrate metrics tracking (impressions and clicks) directly in your controllers.

👁️ Store Impressions (e.g., in index() method) To track impressions when showing a list of items:

```
use AlifAhmmed\MetricsTracker\Helpers\MetricsTracker;

$data = YourModel::all(); // Replace with your model
MetricsTracker::trackImpressionsForCollection($data);
```

This will:

Store an impression only once per user/IP per day

Automatically attach a metric\_token to each model for tracking clicks

🖱️ Store Clicks (e.g., in show() method) To track clicks when a user views or interacts with a single item:

```
use AlifAhmmed\MetricsTracker\Helpers\MetricsTracker;

$data = YourModel::findOrFail($id); // Replace with your model
MetricsTracker::trackClickAndGenerateToken($data);
```

This will:

Store a click only if an impression exists for today

Attach the metric\_token to the model for reference

🔍 2. Filter Metrics by Days You can filter impressions and clicks by a specific range of days using this snippet:

```
$request->validate([
    'days' => 'required|in:1,7,14,30,60,90,180,365',
]);

$days = $request->days;

$metrics = MetricsTracker::getMetricsByDays($days);
```

Accepted values for days: 1, 7, 14, 30, 60, 90, 180, 365

This will return all metrics grouped by:

trackable\_type

type (impression or click)

date

📈 3. Calculate CTR (Click-Through Rate) To calculate CTR for a specific model, ID, and day range, use:

```
use App\Models\YourModel;

$ctr = MetricsTracker::calculateCTR(YourModel::class, $trackableId, 30);
```

Replace YourModel::class with your actual model class.

Replace $trackableId with the model ID.

Replace 30 with any day value (1, 7, 14, 30, 60, 90, 180, 365).

If there are no impressions, the CTR will return 0.

📊 How It Works 👁️ Impression is tracked when an element becomes visible in the viewport.

🖱️ Click is tracked when an element is clicked.

📈 CTR (Click-Through Rate) is calculated based on total clicks / total impressions \* 100.

🛠 Artisan Commands Clean up metrics older than 90 days (adjustable):

```
php artisan metrics:clean
```

🧪 Example Usage (Controller or API) If you're building a SPA or headless app, you can also generate tokens server-side:

```
use AlifAhmmed\MetricsTracker\Helpers\MetricsTracker;

$token = MetricsTracker::generateMetricToken($post);
```

🧑‍💻 Author S M Alif Ahmmed

⚖ License MIT License. Use it freely in personal and commercial projects.

⭐ Like it? Give it a ⭐ on GitHub and share it with your Laravel friends!

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance44

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

440d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/115633805?v=4)[S M ALIF AHMMED](/maintainers/s-m-alif-ahmmed)[@s-m-alif-ahmmed](https://github.com/s-m-alif-ahmmed)

---

Top Contributors

[![s-m-alif-ahmmed](https://avatars.githubusercontent.com/u/115633805?v=4)](https://github.com/s-m-alif-ahmmed "s-m-alif-ahmmed (19 commits)")

---

Tags

laravelhelperpackageactivitycountclickctrimpression

### Embed Badge

![Health badge](/badges/alifahmmed-metrics-tracker/health.svg)

```
[![Health](https://phpackages.com/badges/alifahmmed-metrics-tracker/health.svg)](https://phpackages.com/packages/alifahmmed-metrics-tracker)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k12.5k1](/packages/vinkius-labs-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90142.9k](/packages/emargareten-inertia-modal)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
