Schema for post view tracking (analytics).
Tracks when posts are viewed for analytics purposes. Supports session-based deduplication to avoid counting multiple views from the same visitor.
Fields
post_uuid- Reference to the viewed postuser_uuid- Reference to the viewer (nullable for guests)ip_address- Hashed IP for privacyuser_agent_hash- Hashed browser fingerprintsession_id- Session identifier for deduplicationviewed_at- Timestamp of view
Examples
# Logged-in user view
%PostView{
post_uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
user_uuid: "018e3c4a-1234-5678-abcd-ef1234567890",
ip_address: "hashed_ip",
user_agent_hash: "hashed_ua",
session_id: "session_abc123",
viewed_at: ~U[2025-01-01 12:00:00Z]
}
# Guest view
%PostView{
post_uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
user_uuid: nil,
ip_address: "hashed_ip",
user_agent_hash: "hashed_ua",
session_id: "session_xyz789",
viewed_at: ~U[2025-01-01 13:30:00Z]
}
Summary
Functions
Changeset for creating a post view record.
Hash an IP address for privacy.
Hash a user agent for privacy.
Types
@type t() :: %PhoenixKit.Modules.Posts.PostView{ __meta__: term(), inserted_at: DateTime.t() | nil, ip_address: String.t() | nil, post: PhoenixKit.Modules.Posts.Post.t() | Ecto.Association.NotLoaded.t(), post_uuid: UUIDv7.t(), session_id: String.t() | nil, updated_at: DateTime.t() | nil, user: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t() | nil, user_agent_hash: String.t() | nil, user_uuid: UUIDv7.t() | nil, uuid: UUIDv7.t() | nil, viewed_at: DateTime.t() }