visibility

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package visibility is conditional content (design expansion, M21): the Visibility rule of a section or block, who it shows the block to, and what that does to an email.

A rule lives in the email's MJML, in the block's rc-visible attribute, so it is versioned with the content and kept by language versions. When the email is compiled, every conditional block is wrapped in two markers (mjml.PrepareCompile); a send decides once, when its audience is built, which blocks each recipient doesn't get, and cuts those out of the compiled HTML (Apply). No MJML is compiled per recipient.

Conditions come from a registry (RegisterKind) so later phases add their own: the score and its band (score.go) are in the Engagement group, a paid tier (phase 6) gets a group of its own.

Index

Constants

View Source
const (
	// FixShowEveryone removes a block's rule ("Show the content to everyone").
	FixShowEveryone = "visibility_show_everyone"
	// FixHideBlock hides a block for everyone ("Hide this block for everyone").
	FixHideBlock = "visibility_hide_block"
	// FixRemoveCondition removes one condition of a block's rule ("Remove
	// the condition").
	FixRemoveCondition = "visibility_remove_condition"
)

Fixes Send Readiness offers for conditional content.

View Source
const (
	GroupLists      = "lists"
	GroupContact    = "contact"
	GroupEngagement = "engagement"
)

Groups of the condition picker, in its order. Later phases add theirs (paid tiers get a group of their own); the score and its band are in Engagement (score.go).

View Source
const (
	KindSegment  = "segment"
	KindList     = "list"
	KindTag      = "tag"
	KindField    = "field"
	KindLanguage = "language"
	KindTier     = "tier"
	// The contact's score and its band (contact scoring, score.go).
	KindScore     = "score"
	KindScoreBand = "score_band"
)

Built-in condition kinds.

View Source
const (
	// ShowEveryone is the default: no rule.
	ShowEveryone = "everyone"
	// ShowOnly shows the block to contacts who match the conditions.
	ShowOnly = "only"
	// ShowExcept shows it to everyone except contacts who match.
	ShowExcept = "except"
	// ShowNobody hides it for everyone ("Hide this block for everyone").
	ShowNobody = "nobody"
)

Who sees a block.

View Source
const (
	MatchAll = "all"
	MatchAny = "any"
)

How conditions combine.

View Source
const MaxChecked = 50

MaxChecked is how many versions Send Readiness renders and checks one by one; beyond it, the most common ones plus the largest and the smallest.

Variables

Bands are the score bands in the picker's order.

View Source
var ErrNoBlock = errors.New("that block isn't in the email any more; run the checks again")

ErrNoBlock is a fix for a block the email doesn't have (any more).

View Source
var ErrNoRule = errors.New("visibility: no rule")

ErrNoRule is returned for an element without a Visibility rule.

View Source
var Tiers = []string{"active", "cooling", "at_risk", "sunset"}

Tiers are the engagement tiers in the picker's order.

Functions

func Apply

func Apply(src string, hidden Hidden) string

Apply cuts the hidden blocks out of compiled HTML and removes every marker: the email one recipient gets. HTML without markers comes back as is (minus nothing).

func ApplyWhy

func ApplyWhy(src string, hidden Hidden, line func(id string) string) string

ApplyWhy is Apply for previews: each hidden block becomes a thin line saying what was left out and why ("Hidden: Beta corner · Sam Rivera isn't on Beta Program"); line(id) returns its text, "" to leave it out.

func CountKeys

func CountKeys(src string, audience json.RawMessage) (rules, aud string)

CountKeys are the hashes a count is kept under (visibility_counts): the email's rules and the campaign's audience. The demo seeds the sample's count with them.

func Cut

func Cut(html, hidden string) string

Cut is the email a recipient gets from the compiled HTML of the whole email and their hidden blocks.

func Describe

func Describe(r VisibilityRule, n *Names) string

Describe says a rule in words: the badge on the block ("Beta Program list", "plan is empty", "Except At risk tier and 1 more").

func EmptyLine

func EmptyLine(text string) string

EmptyLine is the preview's box where an empty version has no content.

func Fix

func Fix(src, action string, params map[string]string) (next, label, applied string, err error)

Fix applies a Visibility fix to an email's MJML and returns the new source with the label of the version it saves and the line Review & send shows, in English.

func FixIn

func FixIn(l i18n.Lang, src, action string, params map[string]string) (next, label, applied string, err error)

FixIn is Fix with the line Review & send shows in a reader's language. The version's label stays in English: it joins the other fixes' labels in the version's note.

func LoadFacts

func LoadFacts(ctx context.Context, q *store.Queries, wsID uuid.UUID, ids []uuid.UUID, segs Segments, e Email) (map[uuid.UUID]*Facts, error)

LoadFacts reads what conditions need about some contacts, including what registered kinds load for themselves.

func NewID

func NewID() string

NewID returns a fresh block id: six characters of [a-z0-9].

func Offered

func Offered(tag string) bool

Offered reports whether Visibility can be set on an element of this tag.

func Possible

func Possible(e Email) int64

Possible is how many combinations the blocks allow (2^n, capped).

func PublicHidden

func PublicHidden(src string) string

PublicHidden is the blocks someone who isn't a contact doesn't get (the web archive): every "Only contacts who match" block, none of the "Everyone except" ones.

func Register

func Register(h huma.API, s *Service)

Register adds the conditional content operations.

func RegisterKind

func RegisterKind(k Kind)

RegisterKind adds a condition kind. Later phases call it from their own package's init (phase 6's paid tier).

func Size

func Size(src string, hidden Hidden) int

Size is the size of a version's HTML in bytes, without the markers.

func Validate

func Validate(r VisibilityRule, n *Names) error

Validate checks a rule against the workspace: known kinds and operators, values where the operator needs one. It doesn't check references (a deleted segment is a broken condition, reported by Broken).

func Why

func Why(r VisibilityRule, matched []bool, f *Facts, n *Names) string

Why says why a contact doesn't get a block ("Sam Rivera isn't on Beta Program"): the condition that decided it.

Types

type Audience

type Audience struct {
	Lists           []string `json:"lists"`
	Segments        []string `json:"segments"`
	ExcludeLists    []string `json:"excludeLists"`
	ExcludeLists2   []string `json:"exclude_lists"`
	ExcludeSegments []string `json:"excludeSegments"`
	ExcludeSegs2    []string `json:"exclude_segments"`
	ExcludeTiers    []string `json:"exclude_tiers"`
	ExcludeTiers2   []string `json:"excludeTiers"`
	IncludeSunset   bool     `json:"include_sunset"`
	IncludeSunset2  bool     `json:"includeSunset"`
	// IncludeUnengaged includes or leaves out the unengaged (the sunset
	// tier); unset, a send leaves them out (SR-11).
	IncludeUnengaged  *bool `json:"include_unengaged"`
	IncludeUnengaged2 *bool `json:"includeUnengaged"`
	// Paid is who on the lists gets a paid-only campaign (Earn).
	Paid paidaccess.Audience `json:"-"`
	// RetryOf is the issue a retry campaign sends again to the addresses
	// that were blocked for the sender's reputation (review AN-7).
	RetryOf uuid.UUID `json:"-"`
}

Audience is campaigns.audience as the composer stores it.

func ParseAudience

func ParseAudience(raw json.RawMessage) Audience

ParseAudience reads campaigns.audience (both key styles).

func (Audience) Empty

func (a Audience) Empty() bool

Empty reports whether the audience selects nobody.

type Block

type Block struct {
	ID string
	// Name is the block's name in the layer tree: its own (rc-name, "Beta
	// corner"), else what it is ("text", "2 columns").
	Name string
	Tag  string
	// Path is the element-index path from mj-body, as the composer and the
	// content checks locate elements.
	Path    []int
	Section bool
	Rule    VisibilityRule
	// Parent is the conditional block this one sits in, "" for none: a
	// block inside a hidden one is hidden with it.
	Parent string
}

Block is a conditional block of an email: a section or a content element with a Visibility rule that leaves some contacts out.

type Decision

type Decision struct {
	Hidden  Hidden
	Matched map[string][]bool
}

Decision is what a contact gets: the blocks left out, and for each block whether each condition matched (for "Show why").

func Decide

func Decide(e Email, f *Facts, n *Names) Decision

Decide evaluates every conditional block for a contact. A condition of an unknown kind (a phase's code not loaded) or referring to something deleted never matches.

type Deletion

type Deletion struct {
	Name string
	By   string
	At   time.Time
}

Deletion is who deleted a segment, list or field, and when.

type Email

type Email struct {
	Blocks []Block
	// Sections are mj-body's elements in order, with the conditional block
	// each one is (empty when it isn't).
	Sections []EmailSection
	// Invalid are the rc-visible attributes that couldn't be read.
	Invalid []string
}

Email is what an email's MJML says about conditional content.

func Read

func Read(src string) Email

Read finds an email's conditional blocks. MJML that doesn't parse has none (the compile reports it). The footer is always shown: a rule on it is ignored, as on a block of a kind Visibility isn't offered on.

func (Email) Block

func (e Email) Block(id string) (Block, bool)

Block returns the block with an id.

func (Email) Empty

func (e Email) Empty(hidden map[string]bool) bool

Empty reports whether a version shows nothing between the header and the footer: every content section is hidden (an email with no content sections at all isn't empty because of its rules).

func (Email) Hash

func (e Email) Hash() string

Hash fingerprints the rules (ids and conditions): a count is valid while the rules and the audience stay the same.

func (Email) Refs

func (e Email) Refs() []Ref

Refs lists what the rules refer to, once each.

func (Email) Segments

func (e Email) Segments() []string

Segments lists the segment ids the rules refer to.

type EmailSection

type EmailSection struct {
	Index int
	Label string
	// Role is header, footer or content: a version is empty when it shows
	// no content section.
	Role string
	// Block is the id of the section's own conditional block, if any.
	Block string
}

EmailSection is one top-level element of the body.

type Facts

type Facts struct {
	ID        uuid.UUID
	FirstName string
	LastName  string
	Email     string
	// Lists the contact is subscribed to, and the segments (of those the
	// rules refer to) they are in, by id.
	Lists    map[string]bool
	Segments map[string]bool
	Tags     map[string]bool
	// Attributes are the custom fields.
	Attributes map[string]any
	// Language is the contact's language code as stored ("es-MX").
	Language string
	Tier     string
	// Extra is what kinds load for themselves (Kind.Load), by kind key: the
	// score and band under KindScore.
	Extra map[string]any
}

Facts is what conditions read about one contact. Contacts are read in bulk once per count or send, never one query per contact.

func FinalRecipients

func FinalRecipients(ctx context.Context, q *store.Queries, segs SegmentResolver, wsID uuid.UUID, a Audience, ruleSegments Segments) ([]*Facts, error)

FinalRecipients reads an audience's final recipients the way Send Readiness counts them (suppressed, role and duplicate addresses and contacts the sunset policy stopped left out), with what conditions read.

func (*Facts) Name

func (f *Facts) Name() string

Name is how "Show why" names the contact: their name, else the address.

type Hidden

type Hidden map[string]bool

Hidden is the set of conditional blocks a recipient doesn't get.

func ParseHidden

func ParseHidden(s string) Hidden

ParseHidden reads messages.hidden_blocks ("a1b2c3,d4e5f6").

func (Hidden) String

func (h Hidden) String() string

String writes the set as messages.hidden_blocks stores it: sorted ids, comma-separated, "" for none.

type Kind

type Kind struct {
	Key   string
	Group string
	// Ops are the operators; field conditions take their custom field's
	// operators (FieldOps) instead.
	Ops []Operator
	// Ref names what the condition refers to (zero Ref for none).
	Ref func(c VisibilityCondition) Ref
	// Match decides the condition for a contact.
	Match func(c VisibilityCondition, f *Facts) bool
	// Load reads what Match needs beyond the base facts, for the given
	// contacts, into Facts.Extra. Nil for kinds that read the base facts.
	Load func(ctx context.Context, q *store.Queries, workspaceID uuid.UUID, conditions []VisibilityCondition, facts map[uuid.UUID]*Facts) error
	// Check validates a condition's value beyond "there is one" (nil: any).
	Check func(c VisibilityCondition) error
	// Describe says the condition in words for badges and summaries
	// ("Beta Program list", "plan is empty").
	Describe func(c VisibilityCondition, n *Names) string
	// Why says why a contact doesn't get a block because of this condition
	// ("Sam Rivera isn't on Beta Program"). matched is the condition's result.
	Why func(c VisibilityCondition, f *Facts, matched bool, n *Names) string
	// Options are the values the picker offers for kinds registered by
	// later phases (the catalog's options under the kind's key); nil for
	// none.
	Options func(ctx context.Context, q *store.Queries, workspaceID uuid.UUID, n *Names) ([]VisibilityOption, error)
	// Trait says what the condition reads about a contact for the preview
	// ("Insider · trialing"); nil leaves it out.
	Trait func(c VisibilityCondition, f *Facts, n *Names) string
}

Kind is a condition the picker offers. Built-in kinds are registered in this package; later phases register theirs (RegisterKind) from their own.

func Kinds

func Kinds() []*Kind

Kinds lists the registered kinds in registration order.

func Lookup

func Lookup(key string) (*Kind, bool)

Lookup returns a registered kind.

type LanguageSample

type LanguageSample struct {
	Language string    `json:"language"`
	ID       uuid.UUID `json:"id"`
}

LanguageSample is the contact a base language ("es") is previewed as.

type NamedField

type NamedField struct {
	Label   string
	Type    string
	Options []string
}

NamedField is a custom field.

type Names

type Names struct {
	Lang     i18n.Lang
	Lists    map[string]string
	Segments map[string]string
	Fields   map[string]NamedField
	// Deleted are the segments, lists and fields the workspace deleted,
	// by Ref (who and when, from the audit log). LoadDeletions fills it.
	Deleted map[Ref]Deletion
}

Names resolves what rules refer to, for words and broken conditions.

func LoadNames

func LoadNames(ctx context.Context, q *store.Queries, wsID uuid.UUID) (*Names, error)

LoadNames reads the workspace's lists, segments and fields.

func (*Names) Exists

func (n *Names) Exists(r Ref) bool

Exists reports whether what a condition refers to is still there. Tags always exist: a tag nobody has yet simply matches nobody.

func (*Names) LoadDeletions

func (n *Names) LoadDeletions(ctx context.Context, q *store.Queries, wsID uuid.UUID, refs []Ref) error

LoadDeletions finds who deleted what the rules refer to and is gone.

type Operator

type Operator struct {
	Key     string `json:"key"`
	NoValue bool   `json:"noValue,omitempty"`
}

Operator is one way a kind compares; NoValue operators ("is empty") take no value.

func FieldOps

func FieldOps(typ string) []Operator

FieldOps are the operators of a custom field by its type: the segment builder's.

type Planner

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

Planner decides the hidden blocks of a send's recipients, page by page, while its audience is built. The rules are the source's: language versions keep the source's block ids.

func (*Planner) Hidden

func (p *Planner) Hidden(ctx context.Context, contacts []uuid.UUID) (map[uuid.UUID]string, error)

Hidden decides a page of recipients: their hidden blocks, as messages.hidden_blocks stores them ("" for those who get every block).

type PreviewInput

type PreviewInput struct {
	ContactID string `json:"contactId" format:"uuid"`
	MJML      string `json:"mjml,omitempty" maxLength:"2000000"`
	HTML      string `json:"html,omitempty" maxLength:"2500000"`
}

PreviewInput asks for a contact's version; MJML carries the composer's unsaved rules.

type Ref

type Ref struct {
	Kind string // segment, list, field, tag
	ID   string
}

Ref is what a condition refers to: a segment, a list or a custom field (by id or key). A condition whose reference is gone is broken: Send Readiness blocks until someone fixes it.

type ReportInput

type ReportInput struct {
	MJML string `json:"mjml,omitempty" maxLength:"2000000"`
	HTML string `json:"html,omitempty" maxLength:"2500000"`
	// Recount counts the audience again even when the rules didn't change.
	Recount bool `json:"recount,omitempty"`
}

ReportInput is the content to report on: the composer's unsaved MJML and the HTML it compiled. Empty fields read the saved content.

type Samples

type Samples struct {
	Versions map[string]uuid.UUID `json:"versions"`
	// Languages go from the one most recipients read to the fewest.
	Languages []LanguageSample `json:"languages"`
}

Samples are, for each version (Hidden.String()) and each base language of an audience, its first recipient with a first name, else its first one: the contacts the composer previews the email as (PreviewContacts).

type SegmentResolver

type SegmentResolver interface {
	ContactIDs(ctx context.Context, workspaceID, segmentID uuid.UUID) ([]uuid.UUID, error)
}

SegmentResolver lists a segment's contacts (the audience domain's segments service).

type Segments

type Segments map[string]map[uuid.UUID]bool

Segments is the members of the segments rules refer to, read once per count, send or preview.

func LoadSegments

func LoadSegments(ctx context.Context, r SegmentResolver, wsID uuid.UUID, ids []string, n *Names) (Segments, error)

LoadSegments resolves the segments an email's rules refer to. A segment that no longer exists has no members (its condition is broken).

type Service

type Service struct {
	Pool     *pgxpool.Pool
	Q        *store.Queries
	Segments SegmentResolver
	Log      *slog.Logger
	Now      func() time.Time
}

Service counts versions, previews them and answers what uses what.

func (*Service) BrowserHTML

func (s *Service) BrowserHTML(ctx context.Context, wsID, campaignID, messageID uuid.UUID, html string) string

BrowserHTML is an email shown in the browser: a message's recipient gets their version (view online), anyone else the archive's (no message).

func (*Service) Catalog

func (s *Service) Catalog(ctx context.Context, ws *store.Workspace) (VisibilityCatalog, error)

Catalog returns the condition picker's kinds and values.

func (*Service) HiddenFor

func (s *Service) HiddenFor(ctx context.Context, wsID, campaignID, contactID uuid.UUID) (string, error)

HiddenFor is the blocks a contact doesn't get in a campaign's saved content (a test email sent as that contact).

func (*Service) PreviewAs

func (s *Service) PreviewAs(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID, in PreviewInput) (VisibilityPreview, error)

PreviewAs decides a campaign's conditional blocks for one contact.

func (*Service) PreviewContacts

func (s *Service) PreviewContacts(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID) ([]VisibilityPreviewContact, error)

PreviewContacts picks contacts who get each version, so a person can preview them all from the canvas: one for each version, up to 12 and those with the most recipients first, then one for each other language, up to 16 in all. They are the count's samples while those still get their version; otherwise, and for a member limited to some lists, they are found in the audience again.

func (*Service) PreviewHTML

func (s *Service) PreviewHTML(ctx context.Context, ws *store.Workspace, campaignID, contactID uuid.UUID, src, html string, showWhy bool) (string, *VisibilityPreview, error)

PreviewHTML is the email a contact gets, for the composer's preview: the hidden blocks cut out of html, or, with showWhy, each replaced by a line saying why. src is the source's MJML (its rules decide every language version's blocks).

func (*Service) Report

func (s *Service) Report(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID, in ReportInput) (VisibilityReport, error)

Report describes an email's conditional blocks and counts its versions.

func (*Service) SendPlanner

func (s *Service) SendPlanner(ctx context.Context, wsID, campaignID uuid.UUID) (*Planner, error)

SendPlanner reads a campaign's rules when its send starts. It returns nil when the email has no conditional blocks.

func (*Service) Usage

func (s *Service) Usage(ctx context.Context, ws *store.Workspace, kind, ref string) (VisibilityUsage, error)

Usage finds the unsent emails whose rules refer to a segment, a list (by id), a field (by key) or a tag.

type Tally

type Tally struct {
	Total int64
	// ByHidden counts recipients per hidden set (Hidden.String()).
	ByHidden map[string]int64
	// Shown counts, for each block, the recipients who see it.
	Shown map[string]int64
	// Samples are the contacts to preview the versions as.
	Samples Samples
}

Tally is a count of an audience by version: how many recipients get each set of hidden blocks.

func Count

func Count(e Email, recipients []*Facts, n *Names) Tally

Count decides every recipient and tallies the versions.

type VisibilityBlockInfo

type VisibilityBlockInfo struct {
	ID      string         `json:"id"`
	Name    string         `json:"name"`
	Tag     string         `json:"tag"`
	Path    []int          `json:"path"`
	Section bool           `json:"section"`
	Rule    VisibilityRule `json:"rule"`
	// Words says the rule as the badge does ("Beta Program list").
	Words string `json:"words"`
	// Shown is how many recipients see it; Versions the versions that
	// show it.
	Shown    int64              `json:"shown"`
	Versions []int              `json:"versions"`
	Broken   []VisibilityBroken `json:"broken"`
}

VisibilityBlockInfo is one conditional block of an email.

type VisibilityBroken

type VisibilityBroken struct {
	// Condition is the condition's position in the rule (0-based).
	Condition int    `json:"condition"`
	Kind      string `json:"kind" enum:"segment,list,field"`
	// Name is what it was called ("Customers with mrr over $50").
	Name      string     `json:"name"`
	DeletedBy string     `json:"deletedBy,omitempty"`
	DeletedAt *time.Time `json:"deletedAt,omitempty"`
}

VisibilityBroken is a condition that refers to something deleted.

type VisibilityCampaignPath

type VisibilityCampaignPath struct {
	api.WorkspaceInput
	CampaignID string `path:"campaignId" format:"uuid"`
}

type VisibilityCatalog

type VisibilityCatalog struct {
	// Groups in the picker's order; kinds in each group's order.
	Groups    []string                 `json:"groups"`
	Kinds     []VisibilityCatalogKind  `json:"kinds"`
	Segments  []VisibilityOption       `json:"segments"`
	Lists     []VisibilityOption       `json:"lists"`
	Tags      []VisibilityOption       `json:"tags"`
	Fields    []VisibilityCatalogField `json:"fields"`
	Languages []VisibilityOption       `json:"languages"`
	Tiers     []VisibilityOption       `json:"tiers"`
	Bands     []VisibilityOption       `json:"bands"`
	Score     VisibilityCatalogScore   `json:"score"`
	// Options are the values of kinds later phases register, by kind
	// (paid tiers under "paid").
	Options map[string][]VisibilityOption `json:"options"`
}

VisibilityCatalog is everything the condition picker offers.

type VisibilityCatalogField

type VisibilityCatalogField struct {
	Key     string     `json:"key"`
	Label   string     `json:"label"`
	Type    string     `json:"type"`
	Ops     []Operator `json:"ops"`
	Options []string   `json:"options"`
}

VisibilityCatalogField is a custom field with its operators.

type VisibilityCatalogKind

type VisibilityCatalogKind struct {
	Key   string     `json:"key"`
	Group string     `json:"group"`
	Ops   []Operator `json:"ops"`
}

VisibilityCatalogKind is one condition of the picker. The app names groups, kinds and operators by their keys.

type VisibilityCatalogScore

type VisibilityCatalogScore struct {
	// Configured is false while the workspace has no scoring: nobody has a
	// score or a band yet.
	Configured bool `json:"configured"`
	WarmFrom   int  `json:"warmFrom"`
	HotFrom    int  `json:"hotFrom"`
}

VisibilityCatalogScore is how the workspace's scores fall into bands.

type VisibilityCondition

type VisibilityCondition struct {
	// Kind is a registered condition: segment, list, tag, field, language,
	// tier, and what later phases register.
	Kind string `json:"kind"`
	Op   string `json:"op"`
	// Field is the custom field a field condition reads ("plan").
	Field string `json:"field,omitempty"`
	// Value is a segment or list id, a tag, a field value, a language code,
	// a tier key, a score (0–100) or a score band, depending on the kind.
	Value string `json:"value,omitempty"`
	// To is the top of a score range ("is between Value and To").
	To string `json:"to,omitempty"`
	// Label is the name of the segment or list when it was picked, so a
	// condition still names it after it was deleted.
	Label string `json:"label,omitempty"`
}

VisibilityCondition is one row of the rule: what is checked, how, and against what ("List membership · includes · Beta Program").

type VisibilityHiddenBlock

type VisibilityHiddenBlock struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Why is "Sam Rivera isn't on Beta Program".
	Why string `json:"why"`
}

VisibilityHiddenBlock is a block a contact doesn't get, and why.

type VisibilityOption

type VisibilityOption struct {
	Value    string `json:"value"`
	Label    string `json:"label"`
	Contacts *int64 `json:"contacts,omitempty"`
}

VisibilityOption is a value a condition can take, with how many contacts have it.

type VisibilityPreview

type VisibilityPreview struct {
	ContactID string `json:"contactId"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	// Hidden are the blocks the contact doesn't get; Shown the ids of those
	// they do.
	Hidden []VisibilityHiddenBlock `json:"hidden"`
	Shown  []string                `json:"shown"`
	// Version is the version's number in the versions table (0 when the
	// audience isn't counted), Versions how many there are, Recipients
	// how many get this one.
	Version    int   `json:"version"`
	Versions   int   `json:"versions"`
	Recipients int64 `json:"recipients"`
	// Shows names the conditional blocks it shows ("" for none of them).
	Shows string `json:"shows"`
	// Empty is true when nothing is left between the header and the footer.
	Empty bool `json:"empty"`
	// Traits say what the rules read about the contact ("Active", "plan
	// team", "not on Beta Program").
	Traits []string `json:"traits"`
	// InAudience is false for a contact the campaign wouldn't reach.
	InAudience bool `json:"inAudience"`
}

VisibilityPreview is the version one contact gets.

type VisibilityPreviewContact

type VisibilityPreviewContact struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	Language string `json:"language"`
	// Trait is what sets them apart ("English", "Beta Program").
	Trait string `json:"trait"`
	// Version is the version they get.
	Version int `json:"version"`
}

VisibilityPreviewContact is a contact to preview as: one per version (the most common first), then one per other language.

type VisibilityPreviewContactList

type VisibilityPreviewContactList struct {
	Items []VisibilityPreviewContact `json:"items"`
}

VisibilityPreviewContactList is who the canvas can preview as.

type VisibilityReport

type VisibilityReport struct {
	Blocks   []VisibilityBlockInfo `json:"blocks"`
	Versions []VisibilityVersion   `json:"versions"`
	// Total is the audience's final recipients, as Send Readiness counts them.
	Total int64 `json:"total"`
	// Possible is the number of combinations the blocks allow; Missing how
	// many of them no recipient gets.
	Possible   int64      `json:"possible"`
	Missing    int64      `json:"missing"`
	CountedAt  *time.Time `json:"countedAt,omitempty"`
	DurationMs int        `json:"durationMs"`
	// Counted is false when the audience is empty (nothing to count).
	Counted bool `json:"counted"`
	// MinSize and MaxSize are the smallest and largest version, in bytes.
	MinSize int `json:"minSize"`
	MaxSize int `json:"maxSize"`
	// Checked is how many versions Send Readiness renders one by one.
	Checked int `json:"checked"`
	// Invalid are rules that couldn't be read.
	Invalid []string `json:"invalid"`
}

VisibilityReport is an email's conditional content: its blocks and the versions its audience gets ("3 conditional blocks · 6 versions").

type VisibilityRule

type VisibilityRule struct {
	// ID names the block in compiled HTML markers and in each recipient's
	// hidden blocks. Language versions keep the source's ids.
	ID         string                `json:"id"`
	Show       string                `json:"show" enum:"everyone,only,except,nobody"`
	Match      string                `json:"match,omitempty" enum:"all,any"`
	Conditions []VisibilityCondition `json:"conditions"`
}

VisibilityRule is a block's Visibility setting, as stored in its rc-visible attribute.

func ParseRule

func ParseRule(raw string) (VisibilityRule, error)

ParseRule reads an rc-visible attribute value.

func (VisibilityRule) Conditional

func (r VisibilityRule) Conditional() bool

Conditional reports whether the rule can leave some contacts out.

func (VisibilityRule) Encode

func (r VisibilityRule) Encode() string

Encode writes the rule as the attribute value.

func (VisibilityRule) Shows

func (r VisibilityRule) Shows(matched []bool) bool

Shows decides the rule for a contact: whether the block is shown, given whether each condition matched (in order).

type VisibilityUsage

type VisibilityUsage struct {
	Blocks int                  `json:"blocks"`
	Emails []VisibilityUseEmail `json:"emails"`
}

VisibilityUsage is where something is used by Visibility rules, in emails that haven't gone out yet.

type VisibilityUseEmail

type VisibilityUseEmail struct {
	CampaignID  string     `json:"campaignId"`
	Name        string     `json:"name"`
	Status      string     `json:"status"`
	ScheduledAt *time.Time `json:"scheduledAt,omitempty"`
	// Blocks are the blocks' names ("Annual billing offer"), and Paths
	// where they are (to open the block in the composer).
	Blocks []string `json:"blocks"`
	Paths  [][]int  `json:"paths"`
}

VisibilityUseEmail is an email whose conditional blocks use a segment, list, field or tag.

type VisibilityVersion

type VisibilityVersion struct {
	Number int `json:"number"`
	// Hidden are the ids of the blocks it leaves out; Shown the ones it
	// shows, in the email's order.
	Hidden []string `json:"hidden"`
	Shown  []string `json:"shown"`
	// Shows names what it shows: "Beta corner, Start a free trial", or ""
	// for none of the conditional blocks.
	Shows      string `json:"shows"`
	Recipients int64  `json:"recipients"`
	SizeBytes  int    `json:"sizeBytes"`
	// OverClip is true over Gmail's clipping size (102 KB).
	OverClip bool `json:"overClip"`
	// Empty is true when nothing is left between the header and the footer.
	Empty bool `json:"empty"`
	// Largest and Smallest mark the extremes by size.
	Largest  bool `json:"largest,omitempty"`
	Smallest bool `json:"smallest,omitempty"`
	// Checked is false for versions Send Readiness doesn't render one by one
	// (beyond the 50 with the most recipients, except the extremes).
	Checked bool `json:"checked"`
}

VisibilityVersion is one combination of conditional blocks that some of the audience gets.

func Versions

func Versions(e Email, t Tally, html string) []VisibilityVersion

Versions turns a tally into the versions table: what each shows, how many get it and its size (of the given HTML, the source as compiled).

Jump to

Keyboard shortcuts

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