PhoenixKitWebAnalytics.TrafficFlags (PhoenixKitWebAnalytics v0.6.1)

Copy Markdown View Source

The bits of an event's traffic_flags — traffic that is real but isn't the audience: the site's own people and their networks.

A flagged hit is stored like any other; reports leave it out unless the settings count that kind in, or a report is switched to show it (PhoenixKitWebAnalytics.Reports.filter/1). Nothing is deleted, so a switch flipped back brings the hits back. Rollups only ever hold unflagged traffic.

FlagBitSet when
internal_network1the client address is in a network listed in config :phoenix_kit_web_analytics, internal_networks: […]
admin2the signed-in user holds a role listed in web_analytics_internal_roles
admin_network4the client's network (an IPv4 address, an IPv6 /64) had such a user signed in within web_analytics_admin_network_hours

Bits 8, 16 and 32 are reserved for the suspicious-traffic signals planned next (honeypot, headless, datacenter).

A visit is flagged whole: a hit inherits its session's bits, and a bit that first appears mid-visit is written back to the visit's earlier hits (PhoenixKitWebAnalytics.Collector). How the bits are worked out lives in PhoenixKitWebAnalytics.InternalTraffic.

Summary

Functions

Every defined bit at once — the mask that leaves out all flagged traffic.

The bit of one flag.

Whether a hit with flags is left out under mask — any of its bits among the masked ones.

Every defined flag, {name, bit}, in display order.

The label shown for a flag.

The mask of the bits to leave out, from the names to leave out.

Every defined flag's name.

The names of the bits set in flags.

Types

name()

@type name() :: :internal_network | :admin | :admin_network

Functions

all()

@spec all() :: pos_integer()

Every defined bit at once — the mask that leaves out all flagged traffic.

bit(name)

@spec bit(name()) :: pos_integer()

The bit of one flag.

excluded?(flags, mask)

@spec excluded?(integer() | nil, integer()) :: boolean()

Whether a hit with flags is left out under mask — any of its bits among the masked ones.

flags()

@spec flags() :: [{name(), pos_integer()}]

Every defined flag, {name, bit}, in display order.

label(atom)

@spec label(name()) :: String.t()

The label shown for a flag.

mask(names)

@spec mask([name()]) :: non_neg_integer()

The mask of the bits to leave out, from the names to leave out.

iex> PhoenixKitWebAnalytics.TrafficFlags.mask([:internal_network, :admin_network])
5

names()

@spec names() :: [name()]

Every defined flag's name.

names_in(flags)

@spec names_in(integer() | nil) :: [name()]

The names of the bits set in flags.

iex> PhoenixKitWebAnalytics.TrafficFlags.names_in(6)
[:admin, :admin_network]