2025-06-04 18:17:39 +08:00
|
|
|
|
package gravity
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/oylshe1314/framework/util"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const apiUri = "https://backend.gravity-engine.com/event_center/api"
|
|
|
|
|
const apiEventCollect = "/v1/event/collect/"
|
|
|
|
|
|
|
|
|
|
// 产品名称:逃脱计划(微信)
|
|
|
|
|
const wechatAppId = 11930427
|
|
|
|
|
const wechatBundleId = "wx057a904618b19710"
|
|
|
|
|
const wechatAppKey = "jpXjkmya45lfi6fzGyVvIL2wrPhx7grxYnbsmDJ9ZqgtC0TR8AQvcSdNWieecBtF"
|
|
|
|
|
const wechatAccessToken = "aQND0ibWsKq8oOLXbedTlxzFcek4qxpc"
|
|
|
|
|
const wechatAesKey = "YcuW6Y+1PoBgz+PNqP3tNA=="
|
|
|
|
|
|
|
|
|
|
// 产品名称:逃脱计划(TapTap)
|
|
|
|
|
const tapTapAppId = 16041238
|
|
|
|
|
const tapTapBundleId = "com.qmhd.ttjh.game_1"
|
|
|
|
|
const tapTapAppKey = "DQWb2gVXrrowl7qa0PmcYbtcfnSpn6fNtAljdjhyHJLxwihR8pyegzdkZCBOeu5a"
|
|
|
|
|
const tapTapAccessToken = "Xj9wf1yyeEtDbnjdBg5pGr8snbqivIcm"
|
|
|
|
|
const tapTapAesKey = "OQBXXNxQP6YzDXYrVuJOBQ=="
|
|
|
|
|
|
|
|
|
|
type Properties map[string]any
|
|
|
|
|
|
|
|
|
|
func (properties Properties) Add(name string, value any) {
|
|
|
|
|
if !strings.HasPrefix(name, "$") {
|
|
|
|
|
name = "$" + name
|
|
|
|
|
}
|
|
|
|
|
properties[name] = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (properties Properties) get(name string) any {
|
|
|
|
|
if !strings.HasPrefix(name, "$") {
|
|
|
|
|
name = "$" + name
|
|
|
|
|
}
|
|
|
|
|
return properties[name]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EventType string
|
|
|
|
|
|
|
|
|
|
const EventTypeTrack EventType = "track"
|
|
|
|
|
const EventTypeProfile EventType = "Profile"
|
|
|
|
|
|
|
|
|
|
type EventName string
|
|
|
|
|
|
|
|
|
|
const EventNameCharge EventName = "$PayEvent"
|
|
|
|
|
|
|
|
|
|
type Event struct {
|
|
|
|
|
Type EventType `json:"type"` //事件类型,可选值:track、profile,分别对应用户埋点事件、用户属性事件
|
|
|
|
|
Event EventName `json:"event"` //具体事件英文名称请参考引力后台-设置-元事件
|
|
|
|
|
Time int64 `json:"time"` //事件发生毫秒级时间戳,只接收相对服务器时间在前 10 天至后 1 小时之内的数据,超过范围的数据将不会入库
|
|
|
|
|
TimeFree bool `json:"time_free"` //默认为false、当为true的时候会取消对time参数的校验(一般用于历史数据导入)
|
|
|
|
|
Properties Properties `json:"properties"` //事件属性,具体需要参考 引力引擎后台--设置--元数据 中的内容
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewEvent(tipe EventType, event EventName, properties Properties) *Event {
|
2025-07-16 10:05:22 +08:00
|
|
|
|
return &Event{Type: tipe, Event: event, Time: util.NowMilli(), Properties: properties}
|
2025-06-04 18:17:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Events []*Event
|
|
|
|
|
|
|
|
|
|
func (events Events) Add(tipe EventType, event EventName, time int64, properties Properties) Events {
|
|
|
|
|
return append(events, &Event{
|
|
|
|
|
Type: tipe,
|
|
|
|
|
Event: event,
|
|
|
|
|
Time: time,
|
|
|
|
|
Properties: properties,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MsgEventCollectReq struct {
|
|
|
|
|
ClientId string `json:"client_id"` //用户唯一 ID
|
|
|
|
|
ClientIp string `json:"client_ip,omitempty"` //如果有值,则引力引擎会取该ip作为$ip字段(强制替换)
|
|
|
|
|
ClientUa string `json:"client_ua,omitempty"` //如果有值,则引力引擎会取该ua作为$ua字段(强制替换)
|
|
|
|
|
EventList []*Event `json:"event_list"` //事件列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MsgEventCollectAck struct {
|
|
|
|
|
Code int `json:"code"` //如果收到返回参数,code: 0,则代表数据传输成功
|
|
|
|
|
Msg string `json:"msg"` //信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Reporter func(clientId, clientIp string, event *Event) error
|