heapanalytics

package module
v0.0.0-...-9bb71a3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2016 License: MIT Imports: 5 Imported by: 0

README

go-heapanalytics

Codeship Status for AreaHQ/go-heapanalytics

Provides a simple adapter for using the heap analytics API. See the heap documentation for information on the API covered.

Go Docs

Area

Client options

There are a number of client options that can be set.

The pattern used here is based on Dave Cheneys blog post

It's nice and clean as nil or blank values do not need to be passed in where default values are needed.

Some predefined options have been setup as listed below.

URL

source

Allows you to customise the client base url used by the adapter.

HttpClient

source, example

Allows you to customise the http client used by the adapter.

Examples

Below is example code for using the adapter.

Track using default parameters:
package main

import (
	"fmt"

	"github.com/AreaHQ/go-heapanalytics"
)

func main() {
	// test id used in documentation
	appID := "11"

	c := heapanalytics.NewClient(appID)

	identity := "my@identifier.net"
	event := "test_event"
	properties := map[string]interface{}{"test_prop": "test_val"}

	err := c.Track(identity, event, properties)
	if err != nil {
		fmt.Printf("Error sending track: %s", err.Error())
	} else {
		fmt.Println("Event sent.")
	}
}
Track with HttpClient Option:
package main

import (
	"fmt"
	"net/http"

	"github.com/AreaHQ/go-heapanalytics"
)

func main() {
	// test id used in documentation
	appID := "11"

	// this may be a custom client that you're reusing
	httpClient := http.DefaultClient

	c := heapanalytics.NewClient(appID, heapanalytics.HttpClient(httpClient))

	identity := "my@identifier.net"
	event := "test_event"
	properties := map[string]interface{}{"test_prop": "test_val"}

	err := c.Track(identity, event, properties)
	if err != nil {
		fmt.Printf("Error sending track: %s", err.Error())
	} else {
		fmt.Println("Event sent.")
	}
}
Add user properties using default parameters
package main

import (
	"fmt"
	"net/http"

	"github.com/AreaHQ/go-heapanalytics"
)

func main() {
	// test id used in documentation
	appID := "11"

	// this may be a custom client that you're reusing
	httpClient := http.DefaultClient

	c := heapanalytics.NewClient(appID, heapanalytics.HttpClient(httpClient))

	identity := "my@identifier.net"
	properties := map[string]interface{}{"test_prop": "test_val"}

	err := c.AddUserProperties(identity, properties)
	if err != nil {
		fmt.Printf("Error sending track: %s", err.Error())
	} else {
		fmt.Println("User properties sent.")
	}
}

Documentation

Overview

Package heapanalytics provides a go client for the heap analytics server-side API. See https://heapanalytics.com for more details

Index

Constants

View Source
const (
	// DefaultHost is the default host to use
	DefaultURL = "https://heapanalytics.com"
	//DefaultPathTrack is the default path to use for track events
	DefaultPathTrack = "/api/track"
	//DefaultPathUserProperties is the default path to use for add user properties
	DefaultPathUserProperties = "/api/add_user_properties"
	//ContentType is the type of data to send the API
	ContentType = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a client for the heap API

func NewClient

func NewClient(appID string, options ...ClientOption) *Client

NewClient returns a pointer to a new API client

func (*Client) AddUserProperties

func (c *Client) AddUserProperties(identity string, properties map[string]interface{}) error

Identify posts an API request to the "add user properties" API

func (*Client) Track

func (c *Client) Track(identity, event string, properties map[string]interface{}) error

Track posts an API request to the "track" API

type ClientOption

type ClientOption func(*Client)

ClientOption defines the format of an optional parameter for NewClient

func HttpClient

func HttpClient(client *http.Client) ClientOption

HttpClient is a ClientOption that can be passed into NewClient to change the httpclient used from default

func URL

func URL(url string) ClientOption

Host is an ClientOption that can be passed into NewClient to change the hostname from default

type Event

type Event struct {
	AppID    string `json:"app_id"`
	Identity string `json:"identity"`
	Event    string `json:"event,omitempty"`
	// properties is an interface as it could be a string or int
	Properties map[string]interface{} `json:"properties,omitempty"`
}

Event represents an individual heap event that can be sent to the heap API

func NewEvent

func NewEvent(appID string, identity, event string, properties map[string]interface{}) *Event

Jump to

Keyboard shortcuts

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