lads_run_ad_analytics
LinkedIn Ads read low risk
Part of the LinkedIn Campaign Manager Agent.
What it does
Low-level passthrough to LinkedIn's single reporting endpoint GET /rest/adAnalytics. Runs any of the three finders: q=analytics (exactly 1 pivot), q=statistics (up to 3 pivots), or q=attributedRevenueMetrics (ACCOUNT/CAMPAIGN_GROUP/CAMPAIGN pivots only, 202505+, returns the revenueAttributionMetrics object for CRM-connected accounts). Caller supplies pivot(s), dateRange, timeGranularity, accounts (required: the owning ad accounts, each checked as enabled for Claude) plus optional campaigns/campaign_groups/creatives that narrow the report within them (all as List(urn...)), and optionally the fields= list (omitted: pivotValues, dateRange, impressions, clicks, costInLocalCurrency, costInUsd, landingPageClicks, oneClickLeads, externalWebsiteConversions, videoViews, videoCompletions; for q=attributedRevenueMetrics: revenueAttributionMetrics, dateRange, pivotValues). Returns the raw elements array; adAnalytics is not paged, so there is no paging.total (one call returns up to 15,000 elements; an answer at that cap, or an empty one, carries a note). ACCURACY NOTES: LinkedIn alone returns only impressions+clicks when fields is omitted, which is why the default above is always sent; name any other metric explicitly (max 18 metrics; pivotValues and dateRange are always added). Cost fields (costInLocalCurrency, costInUsd) and revenue/pipeline fields come back as STRINGS — parse to Decimal, never coerce money to float. There is NO money-micros conversion on LinkedIn (unlike Google Ads' divide-by-1e6); amounts are already in major currency units as strings. Every returned number must reconcile to Campaign Manager exactly. When a metric is sliced by a pivot, the per-row values sum to the un-pivoted total — never double-count by adding a pivoted breakdown onto an account roll-up. Use the FORMAT-APPROPRIATE metric (landingPageClicks / LP CTR for Thought Leader and inbound-traffic formats; opens/sends for messaging; quartile completions/CPV for video) — raw clicks/CTR mislead for those formats. Compute prior-period delta by issuing a second call over the immediately preceding equal-length window and differencing.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
finder | enum(analytics|statistics|attributedRevenueMetrics) | yes | Which q= finder to invoke. analytics=exactly 1 pivot; statistics=<=3 pivots; attributedRevenueMetrics=revenue attribution (202505+), ACCOUNT/CAMPAIGN_GROUP/CAMPAIGN pivots only. |
pivots | array<enum> | yes | Pivot dimension(s): CAMPAIGN, CREATIVE, ACCOUNT, CAMPAIGN_GROUP, CONVERSION, MEMBER_COMPANY, MEMBER_JOB_TITLE, MEMBER_SENIORITY, MEMBER_INDUSTRY, MEMBER_COMPANY_SIZE, MEMBER_REGION_V2, MEMBER_COUNTY, MEMBER_JOB_FUNCTION, MEMBER_COUNTRY_V2, etc. (the retired V1 MEMBER_REGION and MEMBER_COUNTRY are sent as their _V2 pivots, with a warning). analytics allows exactly 1; statistics allows <=3. Enum-normalize to UPPER_SNAKE_CASE. |
date_range | string|object | yes | Reporting window, inclusive. Serialized to dateRange=(start:(year:Y,month:M,day:D),end:(...)). Month/day are 1-based integers (no zero padding). Accepts either "YYYY-MM-DD,YYYY-MM-DD" (or a single "YYYY-MM-DD" = start only) OR the object {start:{year,month,day}[, end:{year,month,day}]}; month/day are 1-based integers. |
time_granularity | enum(ALL|DAILY|MONTHLY|YEARLY) | no | Defaults ALL. Prefer ALL for demographic (MEMBER_*) pivots over long ranges to avoid blowing the 15k-element cap. DAILY x pivots multiplies element count fast. |
accounts | array<urn:li:sponsoredAccount> | yes | Required: the ad account(s) the report covers (URNs, or bare ids wrapped to urn:li:sponsoredAccount:{id}); each must be enabled for Claude. campaigns / campaign_groups / creatives narrow the report within them; attributedRevenueMetrics uses the first account. |
campaigns | array<urn:li:sponsoredCampaign> | no | Campaign URN list scope. Bare ids wrapped to urn:li:sponsoredCampaign:{id}. |
creatives | array<urn:li:sponsoredCreative> | no | Creative URN list scope. Bare ids wrapped to urn:li:sponsoredCreative:{id}. NOT valid with attributedRevenueMetrics. |
campaign_groups | array<urn:li:sponsoredCampaignGroup> | no | Campaign-group URN list scope. Bare ids wrapped to urn:li:sponsoredCampaignGroup:{id}. |
fields | array<string> | no | Metric list, max 18 metrics (pivotValues and dateRange are always added and do not count). Omitted: the standard set (pivotValues, dateRange, impressions, clicks, costInLocalCurrency, costInUsd, landingPageClicks, oneClickLeads, externalWebsiteConversions, videoViews, videoCompletions); for q=attributedRevenueMetrics: revenueAttributionMetrics, dateRange, pivotValues. e.g. impressions,clicks,costInUsd,landingPageClicks,oneClickLeads,externalWebsiteConversions,videoViews,opens,sends. Unknown field names 400. |
Safeguards
Policy
Analytics Data may be used only to report/bill the authorizing client. Per LinkedIn Marketing API Terms + Data Storage Requirements: do not retain member-level rows (MEMBER_* pivots) beyond this request, do not combine them with non-official/scraped content, and never pool across unaffiliated accounts to build a demographic, prospecting, or lead database.
Reminder
Reconcile every figure to Campaign Manager; use format-appropriate metrics, never blend formats, parse cost/revenue strings to Decimal, and discard member-level rows after responding.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
TOO_MANY_METRICS | adAnalytics accepts at most 20 fields per call, and Scalix always adds pivotValues and dateRange, so the request may list at most 18 metrics; it listed more. | Trim fields to <=18 or split into multiple calls and merge rows by their pivot key. | no |
TOO_MANY_PIVOTS | q=analytics allows exactly 1 pivot; q=statistics allows up to 3; the request exceeded the finder's pivot limit. | Reduce pivots or switch finder (analytics->statistics). | no |
INVALID_FINDER_PIVOT | q=attributedRevenueMetrics supports only ACCOUNT, CAMPAIGN_GROUP and CAMPAIGN pivots (202505+); CREATIVE/MEMBER_* are rejected. | Use a supported pivot, or switch to q=statistics for CREATIVE/MEMBER_* dimensions. | no |
INVALID_ARGUMENT | LinkedIn rejected a parameter (surfaced verbatim): malformed dateRange, unknown field name, un-encoded or bad URN. | Surface LinkedIn's message verbatim; fix the offending param (percent-encode URNs). Do not guess values. | no |
TOKEN_REVOKED | Access token expired or revoked (HTTP 401). | Refresh once and retry; if still 401, mark needs_reauth and stop. | yes |
PERMISSION_DENIED | Token lacks r_ads_reporting scope, or the account is outside the bearer's scope (HTTP 403). | Request r_ads_reporting and confirm the account is authorized; never touch out-of-scope accounts. | no |
RATE_LIMITED | Daily application/member analytics quota exceeded (HTTP 429). | Back off exponentially (5/10/20s, cap 60s) honoring X-RateLimit-Reset; alert at 75% of daily quota. | yes |
PLATFORM_UNAVAILABLE | LinkedIn returned a 5xx. | Retry with exponential backoff (cap 60s); if persistent, report transient LinkedIn outage. | yes |
Edge cases
- No data in the window, or no read access to it -> success with empty elements and a note, not an error.
- Element cap: LinkedIn returns at most 15,000 elements with NO pagination; an answer that reaches the cap carries a warning that it may be cut short: narrow the date range, reduce pivots, or coarsen granularity.
- Pivot multiplication: a metric sliced by a pivot must not be added back onto the un-pivoted total (double-count risk).
- Demographic (MEMBER_*) rows with <3 events are suppressed by LinkedIn; demographic data is retained only ~2 years.
- Cost AND revenue/pipeline fields arrive as strings — parse to Decimal; never float-coerce money.
- Expired token -> refresh and retry exactly once before surfacing needs_reauth.
- timeGranularity=DAILY over a long range or many entities easily exceeds 15k elements — prefer ALL for demographic pivots.
- attributedRevenueMetrics on an account with no CRM connection returns no rows -> success with a note on what attribution needs, not an error.