承接 jamesfairhurst/laravel-google-analytics-pageviews 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jamesfairhurst/laravel-google-analytics-pageviews

Composer 安装命令:

composer require jamesfairhurst/laravel-google-analytics-pageviews

包简介

Track pageviews server side using the Google Analytics Measurement Protocol.

README 文档

README

Latest Version Software License StyleCI Total Downloads

Don't want nasty tricksy Google Analytics JS tracking code on your site but still want to have some idea of pageviews? This package uses Google's Measurement Protocol to record basic pageviews on your site. It uses a small chunk of Javascript to post page data via Ajax on window load which will get sent to Google using Guzzle.

Currently available for Laravel 5.7 & 5.8, looking into older versions.

Installation

You can install the package via composer:

composer require jamesfairhurst/laravel-google-analytics-pageviews

Optionally, you can publish the config file of the package.

php artisan vendor:publish --provider="JamesFairhurst\LaravelGoogleAnalyticsPageviews\PageviewsServiceProvider" --tag=config

The config file looks like:

<?php

return [
    // Are pageviews tracked?
    'enabled' => env('PAGEVIEWS_ENABLED', true),
    // Site's tracking id
    'google_analytics_tracking_id' => env('PAGEVIEWS_GOOGLE_ANALYTICS_TRACKING_ID', ''),
    // Route name used internally to send pageview to google
    'route' => 'pageviews.store',
];

Usage

Add the Google Analytics Property Tracking ID to your .env file

PAGEVIEWS_GOOGLE_ANALYTICS_TRACKING_ID=UA-xxxxxxx-xx

Next, add the @pageviews blade directive to any page you wish to track or in a layouts file to track all pages e.g.

    <script src="{{ mix('js/app.js') }}"></script>
    @pageviews
</body>

@pageviews will add a small chunk of Javascript that will send a POST XMLHttpRequest request on window.load to a package controller action that will record the pageview using Google's Measurement Protocol.

window.addEventListener("load",function(e){var t=new XMLHttpRequest;t.open("POST","{{ route('pageviews.store') }}",!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send("dp=/home&dt=Home&ua=Mozilla/5.0&dr=https://example.com")});

You can also explicitly disable tracking by adding PAGEVIEWS_ENABLED=false to your .env file which is useful to stop tracking locally.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

统计信息

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

GitHub 信息

  • Stars: 19
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固