MVC:Integration with Posthog on the backend

Problem to solve

目前SaaS没有没有数据产品平台。目前已经决定使用Posthog进行数据平台搭建,需要对产品的前后端进行接入。

Proposal

参考Posthog文档进行开发。

文档:https://posthog.com/docs

接入时,按照 “最小可行性变化”原则,优先完成基础接入。

至少需要

  • Posthog 不应影响现有功能和性能。
  • 采集信息时,应该使用与个人敏感信息无关的标识。且对于临时用户也应有标识。
  • 采集时,应尽量避免采集敏感数据,如密码、私密项目内容等。

Untitled

管理员配置并生效posthog

管理员界面需要配置posthog服务的地址和API_KEY,并确定生效posthog的追踪统计功能。

Key Value Description
api_key phc_Y33jdvhe09v4lrkGD1LrQcC6JWCA211p7Jklhe83 public write-only api key of your PostHog instance, which is used to create events
api_host https://your-posthog.com URL of your PostHog instance (https://app.posthog.com)

mockup: Untitled_1

集成posthog

GitLab 目前已有抽象出来的追踪代码,posthog 同样也可以通过这个实现代码的跟踪。

如代码实例中展示,posthog 的 Action 可以使用 event 的定义,但是需要在其中添加posthog的distinct_id,这里具体值为gitlab的user ID,修改后示例:

# frozen_string_literal: true

module Gitlab
  module Tracking
    module Destinations
      class Base
        def event(category, action, distinct_id, label: nil, property: nil, value: nil, context: nil)
          raise NotImplementedError, "#{self} does not implement #{__method__}"
        end
      end
    end
  end
end

后端统计的指标及范围

依据上文提供的方式,我们本次复制迁移Snowplow的数据跟踪代码及Snowplow现有统计指标到posthog中即可。

User story

  1. 作为公司数据部门,在部署gitlab的数据服务时,我希望能通过简单的配置就能生效对应的数据统计功能。

    Acceptance criteria
    Given 管理员
    When 需要启用PostHog进行统计
    then 勾选启用,配置Posthog的服务和对应的Key,并保存
  2. 作为产品功能的负责人,在进行功能使用分析时,我希望在不读取产品生产数据库的前提下,能获取到用户对于后台服务功能的使用情况数据。

    Acceptance criteria
    Given 用户
    When 使用特定的后台服务,如创建Release
    then 后端通过posthog上报,包含操作User ID、和创建release行为
    posthog 收到该条上报,且内容无误

Intended users

SaaS user.

Links / references

a draft doc about enable posthog in GitLab

Related MR

Baodong 编辑于