usercanal

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 5 Imported by: 0

README

Usercanal Analytics SDK for Go

Go Reference Go Report Card

Overview

Usercanal helps you track user behavior and business metrics across your applications with ease. Built on gRPC, our Go SDK offers efficient event tracking, automatic batching, and type-safe constants, all while providing flexibility for custom analytics.

Installation

Install the SDK with a single command:

go get github.com/usercanal/sdk-go

Quick Start

Start tracking events in just a few minutes!

import (
    "context"
    "github.com/usercanal/sdk-go"
)

func main() {
    // Initialize the UserCanal client
    canal := usercanal.NewClient("YOUR_API_KEY")
    defer canal.Close()

    // Track a simple event
    ctx := context.Background()
    canal.Track(ctx, usercanal.Event{
        UserId: "123",
        Name:   usercanal.FeatureUsed,
        Properties: usercanal.Properties{
            "feature_name": "export",
            "duration_ms": 1500,
        },
    })
}

Key Features

  • Efficient gRPC-based communication for low-latency event tracking
  • Automatic batching and retry mechanisms for reliable data delivery
  • Built-in high availability
    • Automatic DNS-based failover
    • Smart reconnection with exponential backoff
    • No data loss during collector upgrades or outages
  • Built-in support for revenue and subscription tracking with type-safe constants
  • User & Group Analytics to understand user behavior and group dynamics

Explore More

Join Our Community

License

This SDK is distributed under the MIT License. See the LICENSE for more information.

Documentation

Overview

usercanal.go

Index

Constants

View Source
const (
	// User lifecycle events
	UserSignedUp = types.UserSignedUp
	UserLoggedIn = types.UserLoggedIn
	FeatureUsed  = types.FeatureUsed

	// Revenue & Conversion Events
	OrderCompleted       = types.OrderCompleted
	SubscriptionStarted  = types.SubscriptionStarted
	SubscriptionChanged  = types.SubscriptionChanged
	SubscriptionCanceled = types.SubscriptionCanceled
	CartViewed           = types.CartViewed
	CheckoutStarted      = types.CheckoutStarted
	CheckoutCompleted    = types.CheckoutCompleted

	// Currency codes
	CurrencyUSD = types.CurrencyUSD
	CurrencyEUR = types.CurrencyEUR
	CurrencyGBP = types.CurrencyGBP

	// Revenue types
	RevenueTypeSubscription = types.RevenueTypeSubscription
	RevenueTypeOneTime      = types.RevenueTypeOneTime

	// Auth methods
	AuthMethodGoogle = types.AuthMethodGoogle
	AuthMethodEmail  = types.AuthMethodEmail

	// Payment methods
	PaymentMethodCard = types.PaymentMethodCard
)

Re-export constants

Variables

This section is empty.

Functions

func Version

func Version() version.Info

Version returns detailed version information

Types

type Client

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

Client is a facade over the internal API client

func NewClient

func NewClient(apiKey string, cfg ...Config) (*Client, error)

NewClient creates a new client with configuration

func (*Client) Close

func (c *Client) Close() error

func (*Client) DumpStatus

func (c *Client) DumpStatus()

func (*Client) Flush

func (c *Client) Flush(ctx context.Context) error

func (*Client) Group

func (c *Client) Group(ctx context.Context, group GroupInfo) error

func (*Client) Identify

func (c *Client) Identify(ctx context.Context, identity Identity) error

func (*Client) Revenue

func (c *Client) Revenue(ctx context.Context, rev Revenue) error

func (*Client) Track

func (c *Client) Track(ctx context.Context, event Event) error

Re-export main client methods

type Config

type Config struct {
	Endpoint      string        // API Endpoint
	BatchSize     int           // Events per batch
	FlushInterval time.Duration // Max time between sends
	MaxRetries    int           // Retry attempts
	Debug         bool          // Enable debug logging
}

Config holds client configuration

type Currency

type Currency = types.Currency

Re-export types that users need

type Event

type Event = types.Event

Re-export types that users need

type GroupInfo

type GroupInfo = types.GroupInfo

Re-export types that users need

type Identity

type Identity = types.Identity

Re-export types that users need

type Product

type Product = types.Product

Re-export types that users need

type Properties

type Properties = types.Properties

Re-export types that users need

type Revenue

type Revenue = types.Revenue

Re-export types that users need

Directories

Path Synopsis
examples/main.go
examples/main.go
internal
api
api/client.go
api/client.go
batch
batch/batch.go
batch/batch.go
convert
convert/convert.go
convert/convert.go
identity
identity/manager.go
identity/manager.go
logger
logger/logger.go
logger/logger.go
version
version/version.go
version/version.go
types/errors.go
types/errors.go

Jump to

Keyboard shortcuts

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