Skip to main content

Analytics API

The analytics router provides reporting and analysis over scored data -- tier distributions, score timelines, top accounts, conversion attribution, and engagement cadence patterns.

Router namespace: analytics

Source: src/server/trpc/routers/analytics.ts

Procedures

ProcedureTypeAccessDescription
getDistributionquerytenantTier distribution counts by entity type
getScoreHistoryquerytenantScore timeline for a single entity
getTopAccountsquerytenantTop accounts ranked by combined score
snapshotScoresmutationadminSnapshot current engagement scores to history
getConversionAttributionqueryadminSignal-to-conversion correlation analysis
getPipelineCorrelationqueryadminScore tier vs conversion rate analysis
getAccountCadencesquerytenantEngagement cadence patterns across accounts

getDistribution

Returns the count of entities in each score tier for a given entity type.

analytics.getDistribution.queryOptions(input)

Input

FieldTypeRequiredDescription
entityType"person" | "account" | "opportunity"YesEntity type to analyze

Response

{
"entityType": "account",
"distribution": {
"hot": 24,
"warm": 87,
"cool": 156,
"cold": 73
},
"total": 340
}

Example

const trpc = useTRPC();
const { data } = useQuery(
trpc.analytics.getDistribution.queryOptions({ entityType: "account" })
);

getScoreHistory

Returns the score timeline for a single entity over a configurable number of days. Used for trend charts on entity detail pages.

analytics.getScoreHistory.queryOptions(input)

Input

FieldTypeRequiredDefaultDescription
entityIdstringYes--Entity identifier
daysnumber (1-365)No30Number of days of history

Response

[
{
"date": "2026-03-05",
"fitScore": 82.5,
"engagementScore": 67.3,
"combinedScore": 74.9,
"tier": "warm"
},
{
"date": "2026-03-04",
"fitScore": 82.5,
"engagementScore": 71.0,
"combinedScore": 76.8,
"tier": "warm"
}
]

getTopAccounts

Returns the highest-scoring accounts ranked by combined score.

analytics.getTopAccounts.queryOptions(input)

Input

FieldTypeRequiredDefaultDescription
limitnumber (1-100)No10Number of accounts to return

Response

[
{
"accountId": "acc_456",
"accountName": "Acme Corporation",
"fitScore": 92.0,
"engagementScore": 88.5,
"combinedScore": 90.3,
"tier": "hot"
}
]

snapshotScores

Captures the current engagement scores for all entities and writes them to the score history table. This is typically called automatically after scoring runs but can be triggered manually.

analytics.snapshotScores.mutationOptions(options)

Access: Admin only

Input

None.

Response

{
"snapshotId": "snap_abc123",
"entityCount": 1679,
"snapshotAt": "2026-03-05T10:30:00.000Z"
}

getConversionAttribution

Analyzes which engagement signals correlate most strongly with closed-won conversions over a given time period.

analytics.getConversionAttribution.queryOptions(input)

Access: Admin only

Input

FieldTypeRequiredDefaultDescription
daysnumber (1-365)No90Lookback window in days

Response

[
{
"signal": "meeting_attended",
"conversionRate": 0.42,
"sampleSize": 156,
"correlation": 0.68
},
{
"signal": "email_replied",
"conversionRate": 0.31,
"sampleSize": 423,
"correlation": 0.52
}
]
info

Attribution data requires sufficient closed-won deal volume. Results are unreliable with fewer than 30 closed-won deals in the lookback window.


getPipelineCorrelation

Compares conversion rates across score tiers to validate that scoring correlates with actual pipeline outcomes.

analytics.getPipelineCorrelation.queryOptions()

Access: Admin only

Input

None.

Response

[
{ "tier": "hot", "conversionRate": 0.38, "avgDealSize": 125000, "count": 24 },
{ "tier": "warm", "conversionRate": 0.18, "avgDealSize": 82000, "count": 87 },
{ "tier": "cool", "conversionRate": 0.07, "avgDealSize": 45000, "count": 156 },
{ "tier": "cold", "conversionRate": 0.02, "avgDealSize": 31000, "count": 73 }
]

getAccountCadences

Analyzes engagement cadence patterns across accounts -- how frequently accounts engage and whether cadence is accelerating or decelerating.

analytics.getAccountCadences.queryOptions(input)

Input

FieldTypeRequiredDefaultDescription
windownumber (1-180)No30Analysis window in days

Response

[
{
"accountId": "acc_456",
"accountName": "Acme Corporation",
"avgDaysBetweenActivities": 2.3,
"cadenceTrend": "accelerating",
"activityCount": 18,
"tier": "hot"
},
{
"accountId": "acc_789",
"accountName": "Globex Inc",
"avgDaysBetweenActivities": 8.7,
"cadenceTrend": "decelerating",
"activityCount": 5,
"tier": "cool"
}
]
Cadence TrendDescription
acceleratingActivities becoming more frequent
stableConsistent engagement rhythm
deceleratingActivities becoming less frequent
sporadicNo consistent pattern