backstagephp/laravel-google-analytics-v4
backstagephp/laravel-google-analytics-v4 has 36 GitHub stars and 4 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-11 21:14 UTC. Last push 2026-06-23.
Retrieve all data from Google Analytics version 4 using Laravel.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 업데이트 지연
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalLaravel Google Analytics
About Laravel Google Analytics v4
Retrieve all data like pageviews, events, ecommerce transactions and more from Google Analytics version 4 using the Google API.
Installation
You can install the package via composer:
composer require backstage/laravel-google-analytics-v4
You can publish the config file with:
php artisan vendor:publish --tag="google-analytics-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Google Analytics ID
|--------------------------------------------------------------------------
|
| The Google Analytics ID of the website you want to track.
|
*/
'property_id' => env('GOOGLE_ANALYTICS_PROPERTY_ID', null),
/*
|--------------------------------------------------------------------------
| Google Analytics Client Secret
|--------------------------------------------------------------------------
|
| The Google Analytics Client Secret of the website you want to track.
|
*/
'credentials' => env('GOOGLE_ANALYTICS_CREDENTIALS', storage_path('app/analytics/google-credentials.json')),
];
Usage
First you need to create a service account in the Google Cloud Console. You can find the instructions here: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php.
After you have created the service account, you need to download the credentials and save them in the storage/app/analytics folder. You can change the location of the credentials in the config file if you want.
After you have done this, you can use the package like this:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the average session duration for the last 7 days:
$averageSessionDuration = Analytics::averageSessionDuration(Period::days(7));
Available periods
// Set the period to the last x minutes:
Period::minutes(30);
// Set the period to the last x hours:
Period::hours(1);
// Set the period to the last x days:
Period::days(2);
// Set the period to the last x weeks:
Period::weeks(3);
// Set the period to the last x months:
Period::months(4);
// Set the period to the last x years:
Period::years(5);
// Set the period to a custom date range using a Carbon object:
$startDate = Carbon::now()->subDays(7);
$endDate = Carbon::now();
Period::create($startDate, $endDate);
// Set the period to since the given date:
Period::since(Carbon::now()->subDays(7));
Note: Using multiple Carbon objects in the
Period::create()method may possibly result in unexpected behaviour. It is recommended to pass the start and end date as a separate Carbon instance. For example:Period::create(Carbon::instance($startDate), Carbon::instance($endDate)). This will ensure that the start and end date are set correctly.
Available methods
Demographic Analytics
Methods to retrieve demographic analytics data for your website or application. You can use these methods to get information such as the top used languages, total users by city or country and total users per gender. All of the methods take a Period object as a parameter to specify the time range for the analytics data.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the top users by language for the last 7 weeks, limit to top 10:
$data = Analytics::topUsersByLanguage(period: Period::weeks(7), limit: 10);
// Get the total users by language for the last 7 weeks:
$data = Analytics::totalUsersByLanguage(Period::weeks(7));
// Get the top users by city for the last 7 weeks, limit to top 5:
$data = Analytics::topUsersByCity(period: Period::weeks(7), limit: 5);
// Get the total users by city for the last 7 weeks:
$data = Analytics::totalUsersByCity(Period::weeks(7));
// Get the top users by country for the last 7 weeks, limit to top 10:
$data = Analytics::topUsersByCountry(period: Period::weeks(7), limit: 10);
// Get the total users by country for the last 7 weeks:
$data = Analytics::totalUsersByCountry(Period::weeks(7));
// Get the total users by gender for the last 7 weeks:
$data = Analytics::totalUsersByGender(Period::weeks(7));
// Get the total users by age group for the last 7 weeks
$data = Analytics::totalUsersByAgeGroup(Period::weeks(7));
// Get the total users by date per page for the last 7 weeks:
$data = Analytics::totalUsersByDatePerPage(Period::weeks(7));
Device and OS Analytics
Methods to retrieve device and operating system analytics data for your website or application. You can use these methods to get information such as the top popular browsers, screen resolutions, and mobile devices used by your visitors. All of the methods take a Period object as a parameter to specify the time range for the analytics data.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the top users by device category for the last 1 year:
$data = Analytics::topUsersByDeviceCategory(Period::years(1));
// Get the top users by operating system for the last 1 year:
$data = Analytics::topUsersByOperatingSystem(Period::years(1));
// Get the top users by browser for the last 1 year, limit to top 10:
$data = Analytics::topUsersByBrowser(period: Period::years(1), limit: 10);
// Get the total users by browser for the last 1 year:
$data = Analytics::totalUsersByBrowser(Period::years(1));
// Get the top users by screen resolution for the last 1 year, limit to top 5:
$data = Analytics::topUsersByScreenResolution(period: Period::years(1), limit: 5);
// Get the total users by operating system for the last 1 year:
$data = Analytics::totalUsersByOperatingSystem(Period::years(1));
// Get the total users by device category for the last 1 year:
$data = Analytics::totalUsersByDeviceCategory(Period::years(1));
// Get the top users by mobile device branding for the last 1 year, limit to top 10:
$data = Analytics::topUsersByMobileDeviceBranding(period: Period::years(1), limit: 10);
// Get the total users by mobile device branding for the last 1 year:
$data = Analytics::totalUsersByMobileDeviceBranding(Period::years(1));
// Get the top users by mobile device model for the last 1 year, limit to top 10:
$data = Analytics::topUsersByMobileDeviceModel(period: Period::years(1), limit: 10);
// Get the total users by mobile device model for the last 1 year:
$data = Analytics::totalUsersByMobileDeviceModel(Period::years(1));
// Get the top users by mobile input selector for the last 1 year, limit to top 10:
$data = Analytics::topUsersByMobileInputSelector(period: Period::years(1), limit: 10);
// Get the total users by mobile input selector for the last 1 year:
$data = Analytics::totalUsersByMobileInputSelector(Period::years(1));
// Get the top users by mobile device info for the last 1 year, limit to top 10:
$data = Analytics::topUsersByMobileDeviceInfo(period: Period::years(1), limit: 10);
// Get the total users by mobile device info for the last 1 year:
$data = Analytics::totalUsersByMobileDeviceInfo(Period::years(1));
// Get the top users by mobile device marketing name for the last 1 year, limit to top 10:
$data = Analytics::getTopUsersByMobileDeviceMarketingName(period: Period::years(1), limit: 10);
// Get the total users by mobile device marketing name for the last 1 year:
$data = Analytics::getTotalUsersByMobileDeviceMarketingName(Period::years(1));
Pageviews Analytics
Methods to retrieve pageview analytics data for your website or application. You can use these methods to get information such as the total views or by page from your visitors. All of the methods take a Period object as a parameter to specify the time range for the analytics data.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the total pageviews for the last 14 days:
$data = Analytics::totalViews(Period::days(14));
// Get the total pageviews for the last 14 days, grouped by date:
$data = Analytics::totalViewsByDate(Period::days(14));
// Get the total pageviews for the last 14 days, grouped by page:
$data = Analytics::totalViewsByPage(Period::days(14));
// Get the top viewed pages for the last 14 days:
$data = Analytics::topViewsByPage(Period::days(14));
// Get the least viewed pages for the last 14 days:
$data = Analytics::leastViewsByPage(Period::days(14));
// Get the total views for the last 14 days, grouped by page path:
$data = Analytics::totalViewsByPagePath(Period::days(14));
// Get the top viewed pages for the last 14 days, grouped by page path:
$data = Analytics::topViewsByPagePath(Period::days(14));
// Get the total views for the last 14 days, grouped by page title:
$data = Analytics::totalViewsByPageTitle(Period::days(14));
// Get the top viewed pages for the last 14 days, grouped by page title:
$data = Analytics::topViewsByPageTitle(Period::days(14));
// Get the total views for the last 14 days, grouped by page url:
$data = Analytics::totalViewsByPageUrl(Period::days(14));
// Get the top viewed pages for the last 14 days, grouped by page url:
$data = Analytics::topViewsByPageUrl(Period::days(14));
// Get the total views for the last 14 days, grouped by country:
$data = Analytics::totalViewsByCountry(Period::days(14));
// Get the top viewed pages for the last 14 days, grouped by country:
$data = Analytics::topViewsByCountry(Period::days(14));
// Get the total views for the last 14 days, grouped by city:
$data = Analytics::totalViewsByCity(Period::days(14));
// Get the top viewed pages for the last 14 days, grouped by city:
$data = Analytics::topViewsByCity(Period::days(14));
Realtime Analytics
Methods to retrieve realtime analytics data for your website or application. You can use these methods to get information such as the current active visitors on your website. All of the methods take a Period object as a parameter to specify the time range for the analytics data. The default time range is set to 30 minutes when no Period object is passed.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the total active users for the last 30 minutes:
$data = Analytics::activeUsers();
Resource Analytics
Methods to retrieve resource analytics data for your website or application. You can use these methods to get information such as the top landing pages, exit pages and referrers but also your most important social media
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the top 10 referrals for the last 14 days:
$data = Analytics::getTopReferrers(period: Period::days(14), limit: 10);
// Get the top 10 referrals for the last 14 days, by page path:
$data = Analytics::getTopReferrersByPagePath(period: Period::days(14), limit: 10);
// Get the top 10 referrals for the last 14 days, grouped by page title:
$data = Analytics::getTopReferrersByPageTitle(period: Period::days(14), limit: 10);
// Get the top 20 landing pages by page title for the last 14 days:
$data = Analytics::getTopLandingPagesByPageTitle(period: Period::days(14), limit: 20);
// Get the top 20 landing pages for the last 14 days:
$data = Analytics::getTopLandingPages(period: Period::days(14), limit: 20);
// Get the top 20 landing pages with query string by page title for the last 14 days, grouped by page title:
$data = Analytics::getLandingPagesPlusQueryStringAByPageTitle(period: Period::days(14), limit: 20);
// Get the top 5 traffic sources for the last 14 days:
$data = Analytics::getTopTrafficSources(period: Period::days(14), limit: 5);
// Get the top 10 backlinks for the last 14 days:
$data = Analytics::getTopBacklinks(period: Period::days(14), limit: 10);
Sessions Analytics
Methods to retrieve session duration analytics data for your website or application. You can use these methods to get information such as the average session time from your visitors. All of the methods take a Period object as a parameter to specify the time range for the analytics data.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get total sessions for the last 7 days:
$data = Analytics::sessions(Period::days(7));
// Get total sessions for the last 7 days per page:
$data = Analytics::sessionsPerPage(Period::days(7));
// Get the average session duration for the last 7 days:
$data = Analytics::averageSessionDuration(Period::days(7));
// Get the average session duration for the last 7 days, grouped by date:
$data = Analytics::averageSessionDurationByDate(Period::days(7));
// Get the average session duration in seconds for the last 7 days, grouped by page:
$data = Analytics::averageSessionDurationInSecondsByPage(Period::days(7));
// Get the average page views per session for the last 7 days:
$data = Analytics::averagePageViewsPerSession(Period::days(7));
// Get the average page views per session for the last 7 days, grouped by date:
$data = Analytics::averagePageViewsPerSessionByDate(Period::days(7));
// Get the average session duration in seconds for the last 7 days:
$data = Analytics::averageSessionDurationInSeconds(Period::days(7));
// Get the average session duration in seconds for the last 7 days, grouped by date:
$data = Analytics::averageSessionDurationInSecondsByDate(Period::days(7));
// Get bounce rate for the last 7 days:
$data = Analytics::bounceRate(Period::days(7));
// Get bounce rate for the last 7 days, grouped by date:
$data = Analytics::bounceRateByDate(Period::days(7));
// Get bounce rate by page for the last 7 days:
$data = Analytics::bounceRateByPage(Period::days(7));
Users Analytics
Methods to retrieve user analytics data for your website or application. You can use these methods to get information such as the total visitors or amount of visitors per device. All of the methods take a Period object as a parameter to specify the time range for the analytics data.
Here are some examples of how to use the methods:
use Backstage\Analytics\Facades\Analytics;
use Backstage\Analytics\Period;
// Get the total users for the last 5 weeks:
$data = Analytics::totalUsers(Period::weeks(5));
// Get the total users for the last 5 weeks, grouped by date:
$data = Analytics::totalUsersByDate(Period::weeks(5));
// Get the total users for the last 5 weeks, grouped by session source:
$data = Analytics::totalUsersBySessionSource(Period::weeks(5));
// Get the total users for the last 5 weeks, grouped by session medium:
$data = Analytics::totalUsersBySessionMedium(Period::weeks(5));
// Get the total users for the last 5 weeks, grouped by session device:
$data = Analytics::totalUsersBySessionDevice(Period::weeks(5));
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.
Credits
License
The MIT License (MIT). Please see License File for more information.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,618 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,859 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,472 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,495 스타