Skip to content

Commit 84b281a

Browse files
authored
Merge pull request pipeboard-co#30 from florianliebig/feat/insights-attribution-window
Add attribution window option to insights tool
2 parents 1e73a8c + faae54d commit 84b281a

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ For advanced users who need to self-host, the package can be installed from sour
364364
- `time_range`: Time range for insights (default: maximum)
365365
- `breakdown`: Optional breakdown dimension (e.g., age, gender, country)
366366
- `level`: Level of aggregation (ad, adset, campaign, account)
367+
- `action_attribution_windows` (optional): List of attribution windows for conversion data (e.g., ["1d_click", "1d_view", "7d_click", "7d_view"]). When specified, actions and cost_per_action_type include additional fields for each window. The 'value' field always shows 7d_click attribution.
367368
- Returns: Performance metrics for the specified object
368369

369370
21. `mcp_meta_ads_get_login_link`

‎meta_ads_mcp/core/insights.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Insights and Reporting functionality for Meta Ads API."""
22

33
import json
4-
from typing import Optional, Union, Dict
4+
from typing import Optional, Union, Dict, List
55
from .api import meta_api_tool, make_api_request
66
from .utils import download_image, try_multiple_download_methods, ad_creative_images, create_resource_from_image
77
from .server import mcp_server
@@ -11,9 +11,10 @@
1111

1212
@mcp_server.tool()
1313
@meta_api_tool
14-
async def get_insights(object_id: str, access_token: Optional[str] = None,
15-
time_range: Union[str, Dict[str, str]] = "maximum", breakdown: str = "",
16-
level: str = "ad", limit: int = 25, after: str = "") -> str:
14+
async def get_insights(object_id: str, access_token: Optional[str] = None,
15+
time_range: Union[str, Dict[str, str]] = "maximum", breakdown: str = "",
16+
level: str = "ad", limit: int = 25, after: str = "",
17+
action_attribution_windows: Optional[List[str]] = None) -> str:
1718
"""
1819
Get performance insights for a campaign, ad set, ad or account.
1920
@@ -51,6 +52,8 @@ async def get_insights(object_id: str, access_token: Optional[str] = None,
5152
level: Level of aggregation (ad, adset, campaign, account)
5253
limit: Maximum number of results to return per page (default: 25, Meta API allows much higher values)
5354
after: Pagination cursor to get the next set of results. Use the 'after' cursor from previous response's paging.next field.
55+
action_attribution_windows: Optional list of attribution windows (e.g., ["1d_click", "7d_click", "1d_view"]).
56+
When specified, actions include additional fields for each window. The 'value' field always shows 7d_click.
5457
"""
5558
if not object_id:
5659
return json.dumps({"error": "No object ID provided"}, indent=2)
@@ -78,7 +81,11 @@ async def get_insights(object_id: str, access_token: Optional[str] = None,
7881

7982
if after:
8083
params["after"] = after
81-
84+
85+
if action_attribution_windows:
86+
# Meta API expects single-quote format: ['1d_click','7d_click']
87+
params["action_attribution_windows"] = "[" + ",".join(f"'{w}'" for w in action_attribution_windows) + "]"
88+
8289
data = await make_api_request(endpoint, access_token, params)
8390

8491
return json.dumps(data, indent=2)

0 commit comments

Comments
 (0)