lads_get_campaign_analytics
LinkedIn Ads read low risk
Part of the LinkedIn Campaign Manager Agent.
What it does
Convenience reader: per-campaign performance over a date range, pivoting on CAMPAIGN via GET /rest/adAnalytics (q=analytics; time_granularity DAILY/MONTHLY/YEARLY slices it by date). Returns one row per campaign with impressions, clicks, costInUsd/costInLocalCurrency, landingPageClicks, oneClickLeads, externalWebsiteConversions, videoViews and videoCompletions, plus a derived block per row: lp_ctr (landingPageClicks/impressions), lp_cpc and cpv (cost in the account currency per landing-page click / per video view), as decimal strings. ACCURACY NOTES: pick the FORMAT-APPROPRIATE headline metric yourself and say which it is: LP CTR for inbound/Thought-Leader campaigns, opens/sends for SPONSORED_INMAIL/SPONSORED_MESSAGE (request them via fields), view-rate/quartiles for video (request the quartile fields). Cost fields are strings (parse to Decimal); no micros conversion. Every value reconciles to Campaign Manager. Optionally supplies prior-period delta by re-running the immediately preceding equal-length window and differencing each metric.
When to use it
During a full account audit, start with lads_audit_account — it defines the checks, benchmarks, and severity rules this tool's data feeds.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
account | urn:li:sponsoredAccount|string | yes | Owning ad account. Bare numeric id is wrapped to urn:li:sponsoredAccount:{id}; must be within bearer scope. |
campaigns | array<urn:li:sponsoredCampaign|int> | no | Specific campaigns; omit to report all campaigns in the account. Bare ids wrapped to URNs. |
date_range | string|object | yes | Inclusive reporting window {start:{year,month,day},end:{...}}; month/day are 1-based integers. 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 | Default ALL (one row per campaign). DAILY/MONTHLY/YEARLY return one row per campaign per period and multiply the element count. |
fields | array<string> | no | Override metric list (max 18 metrics; pivotValues and dateRange are always added and do not count). It REPLACES the default set, so list every default metric you still want. Default: pivotValues, dateRange, impressions, clicks, costInLocalCurrency, costInUsd, landingPageClicks, oneClickLeads, externalWebsiteConversions, videoViews, videoCompletions. |
include_prior_period | bool | no | If true, a second call covers the equal-length window immediately before date_range (which must be 'YYYY-MM-DD,YYYY-MM-DD') and each element gains prior_period {date_range, metrics, delta_pct} matched by pivot; a zero prior yields null, never 0. A DAILY/MONTHLY/YEARLY time series (several rows per entity) skips the deltas with a warning: use time_granularity ALL. |
Safeguards
Policy
Use this analytics data solely to report to the authorizing client; reconcile to Campaign Manager and never blend a campaign's metrics across differing ad formats — LinkedIn requires format-distinct benchmarks (LP CTR for inbound/TL, opens/sends for messaging).
Reminder
Match Campaign Manager exactly, use the format-appropriate metric, parse cost strings to Decimal, and don't retain member-level data beyond this request.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
CAMPAIGN_NOT_FOUND | One or more campaign URNs do not exist in this account. | Verify campaign ids belong to this account; drop unknown ids before retry. | no |
INVALID_ARGUMENT | LinkedIn rejected a parameter (surfaced verbatim), e.g. malformed dateRange or un-encoded URN. | Surface the message; correct the param. Do not guess. | no |
TOKEN_REVOKED | Token expired/revoked (HTTP 401). | Refresh once and retry; else mark needs_reauth. | yes |
PERMISSION_DENIED | Missing r_ads_reporting, or account out of bearer scope (HTTP 403). | Confirm scope and that the account is authorized. | no |
RATE_LIMITED | Daily reporting quota exceeded (HTTP 429). | Exponential backoff 5/10/20s cap 60s honoring X-RateLimit-Reset. | yes |
PLATFORM_UNAVAILABLE | LinkedIn returned a 5xx. | Retry with backoff; report if persistent. | yes |
Edge cases
- No campaigns, no activity in the window, or no read access to the data -> success with no elements and a note: report no delivery, not zeros.
- LinkedIn returns at most 15,000 rows and does not page: an answer that reaches the cap (DAILY over many campaigns and a long range) carries a warning that it may be cut short; narrow the window.
- derived.lp_ctr is computed whenever a row has landingPageClicks and impressions, and lp_cpc / cpv whenever it has cost and landing-page clicks / video views, whatever the campaign format; for messaging campaigns report opens/sends (request them via fields) as the headline metric, not LP CTR.
- Cost strings parsed to Decimal; never float.
- include_prior_period over a window with no prior data -> delta_pct is null for every metric, never a fabricated 0.
- Rows are per campaign, not grouped by format: report a mixed-format set per format and never roll a single CTR across formats.
- Expired token -> refresh and retry once before needs_reauth.