# `PhoenixKit.Modules.Posts.PostView`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.71/lib/modules/posts/schemas/post_view.ex#L1)

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]
    }

# `t`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.71/lib/modules/posts/schemas/post_view.ex#L45)

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

# `changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.71/lib/modules/posts/schemas/post_view.ex#L90)

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`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.71/lib/modules/posts/schemas/post_view.ex#L109)

Hash an IP address for privacy.

# `hash_user_agent`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.71/lib/modules/posts/schemas/post_view.ex#L116)

Hash a user agent for privacy.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
