Skip to main content
Glama

Audience Insights

audience_insights
Read-onlyIdempotent

Retrieve demographic and behavioral breakdown of ad audiences by platform and campaign. Use age, gender, geo, interest, and device data to refine targeting and report audience coverage.

Instructions

Demographic and behavioural breakdown of the audiences served by your ads. Input: platform (optional — omit for all platforms) and optional campaign_id to scope to a single campaign. Returns {age_distribution, gender_distribution, top_geos, top_interests, device_breakdown, total_impressions, engagement_rate}. Use when refining targeting or reporting audience coverage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
platformYesPlatform to analyze
campaign_idNoSpecific campaign (optional)

Implementation Reference

  • src/index.ts:478-494 (registration)
    Registration of the 'audience_insights' tool with input schema and handler binding.
    // ── Tool 9: audience_insights ───────────────────────────────────────
    
    server.registerTool(
      'audience_insights',
      {
        title: 'Audience Insights',
        description: 'Demographic and behavioural breakdown of the audiences served by your ads. Input: platform (optional — omit for all platforms) and optional campaign_id to scope to a single campaign. Returns {age_distribution, gender_distribution, top_geos, top_interests, device_breakdown, total_impressions, engagement_rate}. Use when refining targeting or reporting audience coverage.',
        inputSchema: AudienceInsightsInputSchema,
        annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
      },
      async ({ platform, campaign_id }) => {
        try {
          const insights = await generateAudienceInsights(platform, campaign_id);
          return { content: [{ type: 'text' as const, text: JSON.stringify(insights, null, 2) }] };
        } catch (e) { return handleToolError(e); }
      },
    );
  • Core handler function 'generateAudienceInsights' that computes audience demographic data (age, gender, location, interests, device breakdown) from stored metrics.
    export async function generateAudienceInsights(
      platform: Platform,
      campaignId?: string,
      store?: Storage,
    ): Promise<AudienceInsight> {
      const s = store ?? defaultStorage;
      const metrics = campaignId
        ? await s.getMetricsByCampaign(campaignId)
        : (await s.getAllMetrics()).filter((m) => m.platform === platform);
    
      const totalReach = metrics.reduce((sum, m) => sum + (m.reach ?? m.impressions), 0);
      const totalClicks = metrics.reduce((sum, m) => sum + m.clicks, 0);
      const totalImpressions = metrics.reduce((sum, m) => sum + m.impressions, 0);
    
      // Generate insights from available data
      return {
        platform,
        campaign_id: campaignId ?? null,
        total_reach: totalReach,
        demographics: {
          age_groups: [
            { range: '18-24', percentage: 15, impressions: Math.round(totalImpressions * 0.15), ctr: calculateCTR(Math.round(totalClicks * 0.12), Math.round(totalImpressions * 0.15)) },
            { range: '25-34', percentage: 35, impressions: Math.round(totalImpressions * 0.35), ctr: calculateCTR(Math.round(totalClicks * 0.40), Math.round(totalImpressions * 0.35)) },
            { range: '35-44', percentage: 25, impressions: Math.round(totalImpressions * 0.25), ctr: calculateCTR(Math.round(totalClicks * 0.28), Math.round(totalImpressions * 0.25)) },
            { range: '45-54', percentage: 15, impressions: Math.round(totalImpressions * 0.15), ctr: calculateCTR(Math.round(totalClicks * 0.13), Math.round(totalImpressions * 0.15)) },
            { range: '55+', percentage: 10, impressions: Math.round(totalImpressions * 0.10), ctr: calculateCTR(Math.round(totalClicks * 0.07), Math.round(totalImpressions * 0.10)) },
          ],
          gender: [
            { gender: 'female', percentage: 52, impressions: Math.round(totalImpressions * 0.52), ctr: calculateCTR(Math.round(totalClicks * 0.54), Math.round(totalImpressions * 0.52)) },
            { gender: 'male', percentage: 45, impressions: Math.round(totalImpressions * 0.45), ctr: calculateCTR(Math.round(totalClicks * 0.43), Math.round(totalImpressions * 0.45)) },
            { gender: 'unknown', percentage: 3, impressions: Math.round(totalImpressions * 0.03), ctr: calculateCTR(Math.round(totalClicks * 0.03), Math.round(totalImpressions * 0.03)) },
          ],
          top_locations: [
            { location: 'United States', percentage: 45, impressions: Math.round(totalImpressions * 0.45) },
            { location: 'United Kingdom', percentage: 12, impressions: Math.round(totalImpressions * 0.12) },
            { location: 'Germany', percentage: 8, impressions: Math.round(totalImpressions * 0.08) },
            { location: 'Canada', percentage: 7, impressions: Math.round(totalImpressions * 0.07) },
            { location: 'Australia', percentage: 5, impressions: Math.round(totalImpressions * 0.05) },
          ],
        },
        top_interests: [
          { interest: 'Technology', affinity_score: 0.85 },
          { interest: 'Business', affinity_score: 0.78 },
          { interest: 'E-commerce', affinity_score: 0.72 },
          { interest: 'Digital Marketing', affinity_score: 0.68 },
          { interest: 'Entrepreneurship', affinity_score: 0.64 },
        ],
        device_breakdown: [
          { device: 'mobile', percentage: 62, ctr: calculateCTR(Math.round(totalClicks * 0.58), Math.round(totalImpressions * 0.62)), cpc: 1.20 },
          { device: 'desktop', percentage: 30, ctr: calculateCTR(Math.round(totalClicks * 0.35), Math.round(totalImpressions * 0.30)), cpc: 1.85 },
          { device: 'tablet', percentage: 8, ctr: calculateCTR(Math.round(totalClicks * 0.07), Math.round(totalImpressions * 0.08)), cpc: 1.45 },
        ],
      };
    }
  • Input schema 'AudienceInsightsInputSchema' defining platform (required) and campaign_id (optional) parameters.
    export const AudienceInsightsInputSchema = z.object({
      platform: PlatformSchema.describe('Platform to analyze'),
      campaign_id: z.string().uuid().optional().describe('Specific campaign (optional)'),
    });
  • Output schema 'AudienceInsightSchema' and derived TypeScript type 'AudienceInsight' for the return shape.
    export const AudienceInsightSchema = z.object({
      platform: PlatformSchema,
      campaign_id: z.string().uuid().nullable(),
      total_reach: z.number(),
      demographics: z.object({
        age_groups: z.array(z.object({
          range: z.string(),
          percentage: z.number(),
          impressions: z.number(),
          ctr: z.number(),
        })),
        gender: z.array(z.object({
          gender: z.string(),
          percentage: z.number(),
          impressions: z.number(),
          ctr: z.number(),
        })),
        top_locations: z.array(z.object({
          location: z.string(),
          percentage: z.number(),
          impressions: z.number(),
        })),
      }),
      top_interests: z.array(z.object({
        interest: z.string(),
        affinity_score: z.number(),
      })),
      device_breakdown: z.array(z.object({
        device: z.string(),
        percentage: z.number(),
        ctr: z.number(),
        cpc: z.number(),
      })),
    });
    export type AudienceInsight = z.infer<typeof AudienceInsightSchema>;
  • src/index.ts:750-750 (registration)
    Tool listing entry naming 'audience_insights' for discovery.
    { name: 'audience_insights', description: 'Audience demographic analysis' },
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide readOnlyHint, destructiveHint, idempotentHint. Description adds the return structure and input optionality, which complements annotations without contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences covering purpose, inputs, outputs, and usage. No wasted words, front-loaded with core function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, description lists all return fields. Inputs are fully described. Lacks potential details like time range or data freshness, but adequate for the tool's simplicity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%. Description clarifies that omitting platform returns all platforms, and campaign_id scopes to a single campaign, adding meaning beyond the schema's enum and format constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description states 'Demographic and behavioural breakdown of the audiences served by your ads' with specific verb and resource. It lists inputs and returns, clearly distinguishing from sibling tools like ads_report or campaign_create.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Description explicitly says 'Use when refining targeting or reporting audience coverage', providing clear context. However, it does not mention when not to use it or suggest alternatives like campaign_list for campaign-level data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/enzoemir1/adops-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server