Skip to content

Provides a simple middleware for server-side piwik tracking

License

Notifications You must be signed in to change notification settings

rossmeier/piwik-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Provides a simple middleware for server-side piwik tracking

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages