PhoenixKit.Modules.Posts.PostView (phoenix_kit v1.7.71)

Copy Markdown View Source

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 post
  • user_uuid - Reference to the viewer (nullable for guests)
  • ip_address - Hashed IP for privacy
  • user_agent_hash - Hashed browser fingerprint
  • session_id - Session identifier for deduplication
  • viewed_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

t()

@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()
}

Functions

changeset(view, attrs)

Changeset for creating a post view record.

Required Fields

  • post_uuid - Reference to post
  • viewed_at - Timestamp of view

Validation Rules

  • viewed_at must not be in the future

hash_ip(ip_address)

Hash an IP address for privacy.

hash_user_agent(user_agent)

Hash a user agent for privacy.