piwik

package module
v0.0.0-...-8a015f6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: MIT Imports: 7 Imported by: 0

README

piwik-middleware

Build Status GoDoc Go Report Card

Piwik is a middleware for macaron that tracks visits via piwik's HTTP Tracking API on the serverside without any visibility for the client.

Installation

go get -u github.com/veecue/piwik-middleware

Usage

package main

import (
	"github.com/veecue/piwik-middleware"
	"gopkg.in/macaron.v1"
)

func main() {
	m := macaron.Classic()
	const piwikenabled = true // this can come from your config
	if piwikenabled {
		m.Use(piwik.Piwik(piwik.Options{
			PiwikURL:  "http://localhost/piwik",
			Token:     "56cee37c8e0df1b6be1ebc66aca6567b",
			WebsiteID: "1",
		}))
	} else {
		// provide fake params so that the website doesn't panic
		m.Map(piwik.FakeTrackingParams())
	}
	m.Get("/", func() string {
		return "Hi"
	})
	m.Get("/search", func(ctx *macaron.Context, tracker *piwik.TrackingParams) {
		// inform piwik about the search without results
		tracker.Search(ctx.Req.URL.Query().Get("q"), 0)
	})
	m.Run()
}

Options

The middleware takes a variety of options:

// Options configures the piwik middleware
type Options struct {
	// The URL of your piwik installation (with our without /piwik.php)
	PiwikURL string

	// Ignore the Do not Track header that is sent by the browser. This is not recommended
	IgnoreDoNotTrack bool

	// The ID of the website in piwik
	WebsiteID string

	// The piwik API's access token
	Token string
}

Contributing

If you have found any bugs or want to propose a new feature, feel free to submit an issue or PR

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ignore

func Ignore(tracker *TrackingParams)

Ignore provides a handler that will hinder all requests from being tracked

func Piwik

func Piwik(options ...Options) macaron.Handler

Piwik returns a new macaron.Handler that sends every request to the piwik tracking API

Types

type Options

type Options struct {
	// The URL of your piwik installation (with our without /piwik.php)
	PiwikURL string

	// Ignore the Do not Track header that is sent by the browser. This is not recommended
	IgnoreDoNotTrack bool

	// The ID of the website in piwik
	WebsiteID string

	// The piwik API's access token
	Token string
}

Options configures the piwik middleware

type TrackingParams

type TrackingParams struct {
	// custom variables that will be assigned to the action (cvar)
	ActionCVar map[string]string

	// custom variables that will be assigned to the visitor (_cvar)
	VisitorCVar map[string]string

	// when this is set to true, no information will be sent to piwik
	Ignore bool
	// contains filtered or unexported fields
}

TrackingParams will be injected into the context and can be used to define piwik actions, like an internal search

func FakeTrackingParams

func FakeTrackingParams() *TrackingParams

FakeTrackingParams returns TrackinParams that can be mapped to the macaron instance when piwik should be disabled

func (*TrackingParams) Search

func (t *TrackingParams) Search(keyword string, params ...interface{})

Search notifies piwik about a search done. Params can be: - the number of search results (int) - the catecory of the search (string)

Jump to

Keyboard shortcuts

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