定制 keithbrink/segment-spark 二次开发

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

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

keithbrink/segment-spark

Composer 安装命令:

composer require keithbrink/segment-spark

包简介

This package adds Segment tracking events to Laravel Spark, including eCommerce events.

README 文档

README

An automatic Segment analytics package for Laravel Spark, which will track all page views and eCommerce events in Segment.

Installation

This version requires PHP 7, and supports Laravel 5.5+ and Spark 5+.

To get the latest version, simply require the project using Composer:

$ composer require keithbrink/segment-spark

On Laravel 5.5+, the KeithBrink\SegmentSpark\SegmentSparkServiceProvider service provider and KeithBrink\SegmentSpark\SegmentSparkFacade facade will be automatically discovered so it will not need to be added to your config. On previous versions, you will need to add those manually to your config/app.php.

Configuration

First, set your Segment write key in your .env file:

MIX_SEGMENT_WRITE_KEY=xxx

Prefixing the property with MIX_ will allow the value to be accessed in Javascript.

Next, you'll need to publish the resources:

$ php artisan vendor:publish --provider="KeithBrink\SegmentSpark\SegmentSparkServiceProvider" --tag=resources

You can also optionally publish the segment-spark.php config file:

$ php artisan vendor:publish --provider="KeithBrink\SegmentSpark\SegmentSparkServiceProvider" --tag=config

The first publish command creates a resources/js/segment-spark.js file, which is a Vue plugin you will need to include in your resources/js/app.js file.

var SegmentSpark = require('./segment-spark.js');
Vue.use(SegmentSpark);

var app = new Vue({
    mixins: [require('spark')]
});

Remember that you will need to run npm run dev to compile your assets.

If you would like to associate server-side analytics requests with the client tracked by Google Analytics, you will need to add an exception for cookie encryption in the EncryptCookies middleware at app\Http\Middleware\EncryptCookies.php:

protected $except = [
    '_ga',
];

It's also a good idea to add User-ID Tracking to Google Analytics.

Usage

After you have set your write key and added Vue plugin to app.js, the package will automatically track all of your page views (including the various tabs on the settings page) and will send events for eCommerce activity, such as viewing, subscribing, renewing, switching, or cancelling a plan.

Logged in users will be automatically tracked using their user ID ($user->id), and their entire user object will be included as traits.

If you are using Google Analytics, the server side events will automatically use the Google Analytics cookie to track events to correct user. Remember to set the server-side tracking ID in Segment's Google Analytics settings.

If you would like to track any custom events, you can use the original Segment class.

Segment::track([
    "event"      => "XXX",
    "properties" => [
        "type" => "Video",
    ]
]);

Or, use the original Javascript Segment library.

analytics.track(event, [properties], [options], [callback]);

Google Analytics Enhanced eCommerce

If you would like to use Google Analytics enhanced eCommerce, this package will automatically track two checkout steps: When the user clicks the Select button on one of the plans (Step 1), and when the user clicks the Subscribe button after filling out their billing information (Step 2). You can name those steps whatever you like in your Google Analytics enhanced eCommerce settings.

Remember that you will need to activate Google Analytics enhanced eCommerce on both Google Analytics and Segment.

License

SegmentSpark is licensed under The MIT License (MIT).

Thanks To

This library borrows code and design structure from AltThree/Segment and Ipunkt/LaravelAnalytics.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固