keithbrink/segment-spark 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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.

keithbrink/segment-spark 适用场景与选型建议

keithbrink/segment-spark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 448 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 keithbrink/segment-spark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 keithbrink/segment-spark 我们能提供哪些服务?
定制开发 / 二次开发

基于 keithbrink/segment-spark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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