clicktoken

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package clicktoken is the click token: an opaque, signed token the click redirect adds to links to a publisher's own sites (stores, as `rc`; and the domains phase 6's conversion API lists, as `rc_click`), so an order or a conversion arriving later can be credited to the email that brought the click. It names the message (so the contact and the campaign or the automation step) and when the click happened; it carries nothing in clear and can't be forged (internal/linktoken's HMAC).

Index

Constants

View Source
const ConversionParam = "rc_click"

ConversionParam carries it on links to the conversion API's domains (phase 6).

View Source
const Kind linktoken.Kind = 201

Kind is the token's linktoken kind (X20's range, 200–209).

View Source
const Param = "rc"

Param is the query parameter that carries the token on links to a store (phase 7).

Variables

View Source
var ErrInvalid = errors.New("clicktoken: invalid token")

ErrInvalid is a token that wasn't signed by this instance.

Functions

func AddUTM

func AddUTM(href string, u UTM) string

AddUTM adds to a link the UTM parameters it doesn't set (the author's choice wins), in the order utm_source, utm_medium, utm_campaign, after its query and before its fragment. Unlike Tag it never re-encodes or reorders what the link already has, so a tagged link still reads as written. Links that aren't Taggable come back unchanged.

func Sign

func Sign(s *linktoken.Signer, c Click) string

Sign returns the token for a click.

func Slug

func Slug(name string) string

Slug turns a campaign's or an automation's name into a utm_campaign value ("October Product Update" → "october-product-update"). Letters lose their marks ("Bản tin tháng 10" → "ban-tin-thang-10"); letters outside ASCII once their marks are gone (中, ж) are dropped.

func Tag

func Tag(link string, utm UTM, token string) string

Tag adds the UTM parameters (where the link doesn't set them already: the author's choice wins) and the click token to a link.

func Taggable

func Taggable(href string) bool

Taggable reports whether AddUTM tags a link: a web link without Liquid (a personalized address is left as written).

Types

type Click

type Click struct {
	WorkspaceID uuid.UUID
	MessageID   uuid.UUID
	ContactID   uuid.UUID
	// At is the click's time, to the minute.
	At time.Time
}

Click is what a token says.

func Verify

func Verify(s *linktoken.Signer, token string) (Click, error)

Verify reads a token.

type UTM

type UTM struct {
	Source   string `json:"source"`
	Medium   string `json:"medium"`
	Campaign string `json:"campaign"`
}

UTM are the parameters a tagged link gets.

func ForEmail

func ForEmail(workspace, name, fallback string) UTM

ForEmail is the UTM of an email's links (Settings › Senders' "Add UTM tags to links"): the workspace's slug, email, and the campaign's or the automation's name as a slug, fallback when the name has nothing a slug keeps.

func (UTM) Key

func (u UTM) Key() string

Key is the query AddUTM gives a link without parameters ("utm_source=acme-newsletter&utm_medium=email&utm_campaign=welcome"): what tells apart the link sets of one email sent with different tags.

Jump to

Keyboard shortcuts

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