sensorsanalytics

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

README

SA-SDK-GO

SensorsAnalytics golang library

Install

go get -u gopkg.in/CuriosityChina/sa-sdk-go.v1

Usage

DefaultConsumer
    url := "http://127.0.0.1:8106/sa?project=default"
    consumer, err := sa.NewDefaultConsumer(url)
    if err != nil {
		log.Fatalln(err)
	}
    // consumer.SetDebug(true)
    defer consumer.Close()
	clt, err := sa.NewClient(consumer, "default", false)
	if err != nil {
		log.Fatalln(err)
    }
    distinctID := "ABCDEFG12345678"
    err = clt.Track(distinctID, "SDKTestEVENT", nil, false)
	if err != nil {
		log.Fatalln(err)
    }
    profile := map[string]interface{}{
			"Age":    33
			"Tag":    "Test",
    }
    err = clt.ProfileSet(distinctID, profile, false)
    if err != nil {
        log.Fatalln(err)
    }
BatchConsumer
    url := "http://127.0.0.1:8106/sa?project=default"
    consumer, err := sa.NewBatchConsumer(url, 20)
    if err != nil {
        log.Fatalln(err)
    }
    // consumer.SetDebug(true)
    defer consumer.Close()
	clt, err := sa.NewClient(consumer, "default", false)
	if err != nil {
		log.Fatalln(err)
    }
    distinctID := "ABCDEFG12345678"
    err = clt.Track(distinctID, "SDKTestEVENT", nil, false)
	if err != nil {
		log.Fatalln(err)
    }
    profile := map[string]interface{}{
			"Age":    33
			"Tag":    "Test",
    }
    err = clt.ProfileSet(distinctID, profile, false)
    if err != nil {
		log.Fatalln(err)
    }
AsyncBatchConsumer
    url := "http://127.0.0.1:8106/sa?project=default"
    consumer, err := sa.NewAsyncConsumer(url, 20, 2000)
    if err != nil {
        log.Fatalln(err)
    }
    // consumer.SetDebug(true)
    defer consumer.Close()
	clt, err := sa.NewClient(consumer, "default", false)
	if err != nil {
		log.Fatalln(err)
    }
    distinctID := "ABCDEFG12345678"
    err = clt.Track(distinctID, "SDKTestEVENT", nil, false)
	if err != nil {
		log.Fatalln(err)
    }
    profile := map[string]interface{}{
			"Age":    33
			"Tag":    "Test",
    }
    err = clt.ProfileSet(distinctID, profile, false)
    if err != nil {
		log.Fatalln(err)
    }

Contributing

  1. Fork it ( https://github.com/CuriosityChina/sa-sdk-go/fork )
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -asm 'Add some feature')
  4. Push to the branch (git push origin new-feature)
  5. Create a new Pull Request

Documentation

Index

Constants

View Source
const SDKVersion = "1.7.1"

SDKVersion sdk 版本号

Variables

View Source
var ErrDebugException = errors.New("Debug模式专用的异常")
View Source
var ErrIllegalDataException = errors.New("在发送的数据格式有误时,SDK会抛出此异常,用户应当捕获并处理。")
View Source
var ErrNetworkException = errors.New("在因为网络或者不可预知的问题导致数据无法发送时,SDK会抛出此异常,用户应当捕获并处理。")
View Source
var (
	// FieldKeywords property key  keyword blacklist
	FieldKeywords = []string{
		"distinct_id",
		"original_id",
		"time",
		"properties",
		"id",
		"first_id",
		"second_id",
		"users",
		"events",
		"event",
		"user_id",
		"date",
		"datetime",
	}
)

Functions

This section is empty.

Types

type AsyncBatchConsumer

type AsyncBatchConsumer struct {
	DefaultConsumer
	// contains filtered or unexported fields
}

AsyncBatchConsumer 异步、批量发送数据的 Consumer。使用独立的线程进行数据发送,当满足以下两个条件之一时进行数据发送:

func NewAsyncBatchConsumer

func NewAsyncBatchConsumer(serverURL string, maxBatchSize int, bufferSize int) (*AsyncBatchConsumer, error)

NewAsyncBatchConsumer 创建新的 AsyncBatchConsumer :param serverURL: 服务器 URL 地址 :param maxBatchSize 单个请求发送的最大大小 :param bufferSize 接收数据缓冲区大小

func (*AsyncBatchConsumer) Close

func (c *AsyncBatchConsumer) Close() error

Close close consumer

func (*AsyncBatchConsumer) Flush

func (c *AsyncBatchConsumer) Flush() error

Flush 用户可以主动调用 flush 接口,以便在需要的时候立即进行数据发送。

func (*AsyncBatchConsumer) Run

func (c *AsyncBatchConsumer) Run() error

Run 运行 Seeder

func (*AsyncBatchConsumer) Send

func (c *AsyncBatchConsumer) Send(msg map[string]interface{}) error

Send 发送数据

func (*AsyncBatchConsumer) Stop

func (c *AsyncBatchConsumer) Stop() error

Stop 停止 Sender

func (*AsyncBatchConsumer) SyncFlush

func (c *AsyncBatchConsumer) SyncFlush() error

SyncFlush 执行一次同步发送。 表示在发送失败时抛出错误。

type BatchConsumer

type BatchConsumer struct {
	DefaultConsumer
	// contains filtered or unexported fields
}

BatchConsumer 批量发送数据的 Consumer,当且仅当数据达到 buffer_size 参数指定的量时,才将数据进行发送。

func NewBatchConsumer

func NewBatchConsumer(serverURL string, maxBatchSize int) (*BatchConsumer, error)

NewBatchConsumer 创建新的 batch consumer

func (*BatchConsumer) Close

func (c *BatchConsumer) Close() error

Close 在发送完成时,调用此接口以保证数据发送完成。

func (*BatchConsumer) Flush

func (c *BatchConsumer) Flush() error

Flush 用户可以主动调用 flush 接口,以便在需要的时候立即进行数据发送。

func (*BatchConsumer) Send

func (c *BatchConsumer) Send(msg map[string]interface{}) error

Send 新的 msg 加入 buffer

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client sensoranalytics client

func NewClient

func NewClient(consumer Consumer, projectName string, timeFree bool) (*Client, error)

NewClient create new client

func (*Client) ClearSuperProperties

func (c *Client) ClearSuperProperties()

ClearSuperProperties 删除所有已设置的事件公共属性

func (*Client) Close

func (c *Client) Close() error

Close 在进程结束或者数据发送完成时,应当调用此接口,以保证所有数据被发送完毕。如果发生意外,此方法将抛出异常。

func (*Client) Flush

func (c *Client) Flush() error

Flush 对于不立即发送数据的 Consumer,调用此接口应当立即进行已有数据的发送。

func (*Client) ProfileAppend

func (c *Client) ProfileAppend(distinctID string, profiles map[string]interface{}, isLoginID bool) error

ProfileAppend 追加一个用户的某一个或者多个集合类型的 Profile。 :param distinct_id: 用户的唯一标识 :param profiles: 用户属性

func (*Client) ProfileDelete

func (c *Client) ProfileDelete(distinctID string, isLoginID bool) error

ProfileDelete 删除整个用户的信息。 :param distinct_id: 用户的唯一标识

func (*Client) ProfileIncrement

func (c *Client) ProfileIncrement(distinctID string, profiles map[string]interface{}, isLoginID bool) error

ProfileIncrement 增减/减少一个用户的某一个或者多个数值类型的 Profile。 :param distinct_id: 用户的唯一标识 :param profiles: 用户属性

func (*Client) ProfileSet

func (c *Client) ProfileSet(distinctID string, profiles map[string]interface{}, isLoginID bool) error

ProfileSet 直接设置一个用户的 Profile,如果已存在则覆盖 :param distinct_id: 用户的唯一标识 :param profiles: 用户属性

func (*Client) ProfileSetOnce

func (c *Client) ProfileSetOnce(distinctID string, profiles map[string]interface{}, isLoginID bool) error

ProfileSetOnce 直接设置一个用户的 Profile,如果某个 Profile 已存在则不设置。 :param distinct_id: 用户的唯一标识 :param profiles: 用户属性

func (*Client) ProfileUnset

func (c *Client) ProfileUnset(distinctID string, profileKeys []string, isLoginID bool) error

ProfileUnset 删除一个用户的一个或者多个 Profile。 :param distinct_id: 用户的唯一标识 :param profile_keys: 用户属性键值列表

func (*Client) RegisterSuperProperties

func (c *Client) RegisterSuperProperties(superProperties map[string]interface{})

RegisterSuperProperties 设置每个事件都带有的一些公共属性,当 track 的 properties 和 super properties 有相同的 key 时,将采用 track 的 :param superProperties 公共属性

func (*Client) Track

func (c *Client) Track(distinctID string, eventName string, properties map[string]interface{}, isLoginID bool) error

Track 跟踪一个用户的行为。 :param distinctID: 用户的唯一标识 :param eventName: 事件名称 :param properties: 事件的属性

func (*Client) TrackSignup

func (c *Client) TrackSignup(distinctID string, originalID string, properties map[string]interface{}) error

TrackSignup 这个接口是一个较为复杂的功能,请在使用前先阅读相关说明:http://www.sensorsdata.cn/manual/track_signup.html, 并在必要时联系我们的技术支持人员。 :param distinct_id: 用户注册之后的唯一标识 :param original_id: 用户注册前的唯一标识 :param properties: 事件的属性

type ConsoleConsumer

type ConsoleConsumer struct {
}

ConsoleConsumer 将数据直接输出到标准输出

func NewConsoleConsumer

func NewConsoleConsumer() *ConsoleConsumer

NewConsoleConsumer 创建新的 ConsoleConsumer

func (*ConsoleConsumer) Close

func (c *ConsoleConsumer) Close() error

Close close consumer

func (*ConsoleConsumer) Flush

func (c *ConsoleConsumer) Flush() error

Flush 用户可以主动调用 flush 接口,以便在需要的时候立即进行数据发送。

func (*ConsoleConsumer) Send

func (c *ConsoleConsumer) Send(msg map[string]interface{}) error

Send 发送数据

type Consumer

type Consumer interface {
	Send(message map[string]interface{}) error
	Flush() error
	Close() error
}

Consumer sensors analytics consumer data

type DebugConsumer

type DebugConsumer struct {
	// contains filtered or unexported fields
}

DebugConsumer 调试用的 Consumer,逐条发送数据到服务器的Debug API,并且等待服务器返回的结果 具体的说明在http://www.sensorsdata.cn/manual/

func NewDebugConsumer

func NewDebugConsumer(serverURL string, writeData bool) (*DebugConsumer, error)

NewDebugConsumer 创建新的调试 consumer

func (*DebugConsumer) Close

func (c *DebugConsumer) Close() error

Close 在发送完成时,调用此接口以保证数据发送完成。

func (*DebugConsumer) Flush

func (c *DebugConsumer) Flush() error

Flush 用户可以主动调用 flush 接口,以便在需要的时候立即进行数据发送。

func (*DebugConsumer) Send

func (c *DebugConsumer) Send(msg map[string]interface{}) error

Send 发送数据

type DefaultConsumer

type DefaultConsumer struct {
	// contains filtered or unexported fields
}

DefaultConsumer 默认的 Consumer实现,逐条、同步的发送数据给接收服务器。

func NewDefaultConsumer

func NewDefaultConsumer(serverURL string) (*DefaultConsumer, error)

NewDefaultConsumer 创建新的默认 Consumer :param serverURL: 服务器的 URL 地址。

func (*DefaultConsumer) Close

func (c *DefaultConsumer) Close() error

Close close consumer

func (*DefaultConsumer) Flush

func (c *DefaultConsumer) Flush() error

Flush flush data

func (*DefaultConsumer) Send

func (c *DefaultConsumer) Send(msg map[string]interface{}) error

Send 发送数据

func (*DefaultConsumer) SetDebug

func (c *DefaultConsumer) SetDebug(debug bool)

SetDebug enable/disable consumer debug

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL