定制 jakeydevs/analytics 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jakeydevs/analytics

Composer 安装命令:

composer require jakeydevs/analytics

包简介

A self-hosted analytic system for Laravel

README 文档

README

Analytics is a simple website analytic package for Laravel giving you just enough data to be practical without any of the data-sharing, third party crazyness you get with hosted web analytic tools.

This plugin is being actively developed on stream by https://www.twitch.tv/jakeydev.

Installation

System built on Laravel 8. Not tested on anything under version 8.

$ composer require jakeydevs/analytics

Once installed, run migrations to allow the system to record pageviews! To edit the configuration for the package, you can publish the config file to make edits:

php artisan vendor:publish --provider="Jakeydevs\Analytics\AnalyticServiceProvider" --tag="config"

Record Pageviews

Recorded Pageviews

To record pageviews, you'll need to add a specific middleware to your routes. This middleware, when ran, will save each pageview to the system. The middleware is named pageview.

To save on all pageviews to your system set the middleware to run when the web routes are ran. The best way to do this is by setting the middleware on the RouteServiceProvider

app\Providers\RouteServiceProvider.php

Route::middleware(['web', 'pageview'])
  ->namespace($this->namespace)
  ->group(base_path('routes/web.php'));

Provided methods

Dates

Dates should be passed to the analytics model in as a Period. Examples are:

Period::days(7) //-- Gets the last 7 days
Period::days(0) //-- Gets today
Period::create(now(), now()->subMinutes(10)) //-- Gets last 10 minutes

You can also get a set of dates to compare to your period - useful for providing context to results - by using the compare method. Examples are

$period = Period::days(7);
$compare = Period::compare($period); //-- Gets the 7 days before that

$period = Period::days(0);
$compare = Period::compare($period); //-- Gets yesterdays data

Analytic Methods

You can use these methods to get pageviews, unique sessions, the bounce rate or the average duration of time for a session (in seconds):

Jakeydevs\Analytics\Analytics::getPageviews(Period $period): int
Jakeydevs\Analytics\Analytics::getUnique(Period $period): int
Jakeydevs\Analytics\Analytics::getBounceRate(Period $period): float
Jakeydevs\Analytics\Analytics::getDuration(Period $period): int

You can also get aggregated information for any of the parsed data gathered (browser, os, device, location, paths).

Jakeydevs\Analytics\Analytics::getDataAggregate(Period $period, string $column): array

The data returned is an array with the column and sessions ordered high to low.

View Components

The system comes with several view components out the box for working with the data. They are based on Tailwind and the design can be found below.

1

You can use these with the tags:

@php
$p = Period::days(7);
@endphp

<!-- Blade file -->
<x-analytics-uniques :p="$p"/>
<x-analytics-views :p="$p"/>
<x-analytics-bounce :p="$p"/>
<x-analytics-duration :p="$p"/>

FAQ

Is this GDPR comliant? I think so? I am not a lawyer - and if you are not either, you should totally talk to one if you are worried about GDPR.

Does this work on SPAs At the moment no as it only records a pageview on a page request.

Contributing

Contributions are welcome - please send a pull request. When the project matures we'll add more detailed contribution guidelines!

This repo is available as part of Hacktoberfest 2020 and is perfect for first timers! If you need help, please join me on streams on Tuesdays and Fridays between 1pm and 4pm (GMT)!

Features

Please feel free to add pull requests for any of the below crossed - or ask for new features in the issues.

✅ Record a pageview (Middleware) ✅ Get data from system ✅ Parsing configuration ❌ Record a pageview (manually - useful for SPA) ❌ View components for basic analytics ❌ Tests ❌ How to add own data parsers ❌ Example dashboard

License

MIT

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固