gowoopra

package module
v0.0.0-...-f85a7ee Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2016 License: MIT Imports: 4 Imported by: 0

README

Gowoopra

Build Status Goreport godoc badge

Golang SDK for Woopra API based on API documentation

Usage:

// defining new reusable Tracker with custom settings
wt, _ := gowoopra.NewTracker(map[string]string{

    // `host` is domain as registered in Woopra, it identifies which
    // project environment to receive the tracking request
    "host": "medcare.clinic",

    // In milliseconds, defaults to 30000 (equivalent to 30 seconds)
    // after which the event will expire and the visit will be marked
    // as offline.
    "timeout": 30000,
})

person := gowoopra.Person{
    Name: "Miles Davis",
    Email:"coltrane@johns.com",
}

// sending User-Agent HTTP header content as an optional argument
userAgent := r.UserAgent() // r is an idiomatic http.Request

// identifying current visitor in Woopra
id := wt.Identify(person, userAgent)

// Tracking custom event in Woopra. Each event can has additional data
id.Track(
    "login",           // event name
    map[string]string{ // custom data
        "through": "mobile",
        "when":    "yesterday",
        "mood":    "Really good",
    })

// it's possible to send only visitor's data to Woopra, without sending 
// any custom event and/or data
id.Push()

License:

Copyright (c) 2016 Serhii Herasymov

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Example
// Sample package usage:
wt, _ := NewTracker(map[string]string{
	"host": "sample-host.com",
})

wt.Identify(
	Person{"John Coltrane", "coltrane@johns.com"},
).Track("login", map[string]string{
	"through": "mobile",
	"when":    "yesterday",
	"mood":    "Really good",
})
Output:

Index

Examples

Constants

View Source
const (
	// To track events in Woopra, send Http GET requests to:
	TRACK_API_ENDPOINT = "https://www.woopra.com/track/ce"

	// Identify requests can be used to ID a visitor and/or add properties to that visitor. The endpoint is:
	IDENTIFY_API_ENDPOINT = "https://www.woopra.com/track/identify"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Tracker
	Person
	Event             string
	VisitorProperties map[string]string
	UserAgent         string
}

Context is an intermediate representation of concatenated track-request specific data

func (*Context) Push

func (ctx *Context) Push() *Context

Push identify a user without any tracking event

func (*Context) Track

func (ctx *Context) Track(event string, properties map[string]string) *Context

Track is tracking a custom event for identified person

type Person

type Person struct {
	Name  string
	Email string
}

Person used for identifying person (user) for upcoming tracking

type Tracker

type Tracker struct {
	Host    string
	Timeout int
}

Tracker used for storing sharable settings

func NewTracker

func NewTracker(config map[string]string) (*Tracker, error)

NewTracker creates new instance of sharable Tracker struct

func (Tracker) Identify

func (t Tracker) Identify(person Person, args ...string) *Context

Identify is used to create reusable person-specific association. Last (optional) argument is used to proxy UserAgent data to Woopra

Example
// Usage with proxying client's `User-agent` to Woopra
wt, _ := NewTracker(map[string]string{
	"host": "medcare.clinic",
})

wt.Identify(
	Person{"Miles Davis", "coltrane@johns.com"},

	// can be grabbed with http.Request.UserAgent()
	"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7",
).Track("login",
	map[string]string{
		"through": "mobile",
		"when":    "yesterday",
		"mood":    "Really good",
	})
Output:

Jump to

Keyboard shortcuts

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