tracking

package
v0.0.0-...-8bff5d1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tracking provides privacy-focused user tracking functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Footprint

func Footprint(r *http.Request, salt string) (string, error)

Footprint takes user non-private information and generates a hash. The hash is unique for the visitor, not for the page.

func GetUserIP

func GetUserIP(r *http.Request) string

GetUserIP returns the IP from given request. It will try to extract the real client IP from headers if possible.

Types

type Handler

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

Handler handles tracking endpoints.

func NewHandler

func NewHandler(service Tracker) Handler

NewHandler returns a new tracking handler.

func (*Handler) DeleteHit

func (h *Handler) DeleteHit() http.HandlerFunc

DeleteHit prints the hit with the specified day.

func (*Handler) GetHits

func (h *Handler) GetHits() http.HandlerFunc

GetHits retrieves total amount of hits stored.

func (*Handler) SearchHit

func (h *Handler) SearchHit() http.HandlerFunc

SearchHit returns the hits that matched with the search.

func (*Handler) SearchHitByField

func (h *Handler) SearchHitByField() http.HandlerFunc

SearchHitByField returns the hits that matched with the search.

type Hit

type Hit struct {
	ID        string    `json:"id"`
	Footprint string    `json:"footprint"`
	Path      string    `json:"path"`
	URL       string    `json:"url"`
	Language  string    `json:"language"`
	UserAgent string    `json:"user_agent" db:"user_agent"`
	Referer   string    `json:"referer"`
	Date      time.Time `json:"date"`
}

Hit represents a single data point/page visit.

func HitRequest

func HitRequest(r *http.Request, salt string) (*Hit, error)

HitRequest generates a hit for each request.

func (*Hit) String

func (hit *Hit) String() (string, error)

String returns the string representation of a hit.

type Hitter

type Hitter struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

Hitter provides methods to hit requests and store them in a data store.

func (*Hitter) Delete

func (h *Hitter) Delete(ctx context.Context, id string) error

Delete takes away the hit with the id specified from the database.

func (*Hitter) Get

func (h *Hitter) Get(ctx context.Context) ([]Hit, error)

Get lists all the hits stored in the database.

func (*Hitter) Hit

func (h *Hitter) Hit(ctx context.Context, r *http.Request) error

Hit stores the given request. The request might be ignored if it meets certain conditions.

func (*Hitter) Search

func (h *Hitter) Search(ctx context.Context, query string) ([]Hit, error)

Search looks for a value and returns a slice of the hits that contain that value.

func (*Hitter) SearchByField

func (h *Hitter) SearchByField(ctx context.Context, field, value string) ([]Hit, error)

SearchByField looks for a value and returns a slice of the hits that contain that value.

type Searcher

type Searcher interface {
	Search(ctx context.Context, value string) ([]Hit, error)
	SearchByField(ctx context.Context, field, value string) ([]Hit, error)
}

Searcher is the interface that wraps hits search methods.

type Tracker

type Tracker interface {
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context) ([]Hit, error)
	Hit(ctx context.Context, r *http.Request) error
	Searcher
}

Tracker is the interface that wraps user tracking methods.

func NewService

func NewService(db *sqlx.DB) Tracker

NewService returns a new user tracker.

Jump to

Keyboard shortcuts

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