You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Graph API或Facebook Web SDK获取特定URL的页面浏览量?

How to Retrieve Page Views for a Specific URL via Facebook Tools

Great question! When you use window.FB.AppEvents.logPageView() to log page views, that data gets sent to Meta's event infrastructure (formerly Facebook Analytics). To programmatically fetch the page view count for a specific URL, you'll need to use the Graph API—the Facebook Web SDK doesn't include methods to query historical event data directly. Here's how to do it:

Prerequisites First

Before you start, make sure you have:

  • Admin or Analytics access to the Facebook/Meta app associated with your page views.
  • A valid access token: Use an app access token (best for server-side calls to avoid exposing sensitive permissions) or a user access token with ads_read and/or business_management permissions.

Option 1: Query Raw Page View Events (Graph API)

If you want to pull individual page view events filtered by your target URL, use the /{app-id}/app_events endpoint. This lets you fetch granular event data matching your criteria.

Example Request

GET /{your-app-id}/app_events?
  event=page_view&
  fields=id,created_time,parameters&
  filter=[{"field":"url","operator":"EQUAL","value":"https://your-target-url.com"}]&
  access_token={your-access-token}

Breakdown of Parameters:

  • event=page_view: Filters results to only include page view events.
  • fields: Specifies which data points to return (here, event ID, timestamp, and the parameters sent with the event).
  • filter: Narrows results to only events where the url parameter matches your target URL. Note: If you passed a custom URL via logPageView({url: "custom-url"}), adjust the field value to match your custom parameter key.

Option 2: Get Aggregated Page View Metrics (Insights API)

If you want a summarized count of page views per URL (instead of individual events), use the /{app-id}/insights endpoint. This returns aggregated metrics, which is ideal for reporting.

Example Request

GET /{your-app-id}/insights?
  metric=page_views&
  breakdown=url&
  period=day&
  since=2024-01-01&
  until=2024-01-31&
  access_token={your-access-token}

Breakdown of Parameters:

  • metric=page_views: Targets the page view count metric.
  • breakdown=url: Splits the metric by page URL, so you get a count for each unique URL.
  • period: Defines the time range (use day, week, month, or lifetime).
  • since/until: Narrows the results to a specific date range.

Key Notes

  • Data Delay: Meta's event data isn't real-time—expect a delay of 15 minutes to a few hours before new page views show up in API results.
  • Frontend vs. Server-Side: Always make Graph API calls from your server, not the frontend. Exposing access tokens in client-side code risks unauthorized access to your app's data.
  • Custom Parameters: If you customized the logPageView() call with additional parameters (e.g., window.FB.AppEvents.logPageView({content_url: "your-url"})), adjust the filter or breakdown field to match your custom parameter name.

内容的提问来源于stack exchange,提问作者Mike Ng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:41:02