Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Priyanshu471/ad-management/llms.txt

Use this file to discover all available pages before exploring further.

The Campaign model represents an advertising campaign created by a user in the Ad Management System. Defined in models/campaign.ts, it stores all campaign metadata — from creative details like title and description to performance metrics like impressions, clicks, and click-through rate. Each campaign holds a required reference to the User who owns it, establishing a many-to-one relationship between campaigns and advertisers.

Schema

models/campaign.ts
import mongoose, { Schema, models } from "mongoose";

const campaignSchema = new Schema(
  {
    title:       { type: String, required: true },
    description: { type: String, required: true },
    objective:   { type: String, required: true },
    status:      { type: String, default: "Active" },
    impressions: { type: Number },
    click:       { type: Number },
    ctr:         { type: String },
    budget:      { type: String, required: true },
    duration:    { type: String, required: true },
    user:        { type: Schema.Types.ObjectId, ref: "User", required: true },
  },
  { timestamps: true }
);

const Campaign = models.Campaign || mongoose.model("Campaign", campaignSchema);
export default Campaign;

Fields

_id
ObjectId
Auto-generated unique identifier assigned by MongoDB on document creation.
title
String
required
The campaign name displayed across the advertiser and admin dashboards.
description
String
required
A short description summarising the campaign’s purpose or creative direction.
objective
String
required
The campaign’s marketing objective. See the Campaign Objectives section for all nine accepted values.
status
String
The current lifecycle state of the campaign. Defaults to "Active" on creation. The schema accepts any string — no enum constraint is applied at the database layer.
impressions
Number
Optional. The total number of times the campaign’s ad has been displayed.
click
Number
Optional. The total number of clicks the campaign’s ad has received.
ctr
String
Optional. The click-through rate, stored as a string (e.g. "5" represents 5%). See the note below on string storage.
budget
String
required
The allocated budget for the campaign (e.g. "50000" or "10,000"). See the note below on string storage.
duration
String
required
The intended run length of the campaign (e.g. "30 days").
user
ObjectId
required
A reference to the User document that owns this campaign. Populated via ref: "User".
createdAt
Date
Timestamp automatically set by Mongoose when the document is first created.
updatedAt
Date
Timestamp automatically updated by Mongoose whenever the document is modified.

Sample Document

{
  "_id": "65f1a2b3c4d5e6f7a8b9c0d2",
  "title": "Summer Sale 2024",
  "description": "Promote summer collection",
  "objective": "Conversions",
  "status": "Active",
  "impressions": 10000,
  "click": 500,
  "ctr": "5",
  "budget": "50000",
  "duration": "30 days",
  "user": "65f1a2b3c4d5e6f7a8b9c0d1",
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Campaign Objectives

The objective field accepts one of nine values sourced from the application’s campaignObjective array in lib/data.ts. These represent standard digital advertising goals:

String Fields

Both budget and ctr are stored as String rather than Number in MongoDB. This is intentional — string storage allows flexible display formatting such as comma-separated budget values (e.g. "10,000") and percentage representations for CTR (e.g. "5" for 5%), without requiring transformation at the database layer. Parse these fields to a number only when arithmetic operations (such as aggregation or comparison) are needed at the application level.

Querying by User

To fetch all campaigns belonging to a specific advertiser, filter on the user field using the owner’s ObjectId:
import Campaign from "@/models/campaign";

const campaigns = await Campaign.find({ user: userId });
To also resolve the full user document in the same query, chain .populate("user"):
const campaigns = await Campaign.find({ user: userId }).populate("user");

Build docs developers (and LLMs) love