APIの使用

スタートガイドのページにある前提条件を満たしているなら、このページで、イベントの送信方法やイベントテストツールの使い方についてご確認ください。イベントを送信したら、設定を検証してください。

コンバージョンAPIは、FacebookのグラフAPIの上に構築された、マーケティングAPIがベースになっています。マーケティングAPIとグラフAPIでは、バージョン廃止スケジュールが異なっています。リリースサイクルはグラフAPIに合わせたものであるため、どのバージョンも少なくとも2年間はサポートされます。この例外事項は、コンバージョンAPIについてのみ有効です。

コンバージョンAPI: 概要パラメーター

コンバージョンAPIを使用して共有されるウェブ、アプリ、実店舗イベントには特定のパラメーターが必要です。コンバージョンAPIを使用することで、自分が知る限りaction_sourceパラメーターが正確であることに同意するものとします。必須パラメーターのリストはこちらをご覧ください。

リクエストの送信

新しいイベントを送信するには、次のパスからこのAPIの/eventsエッジにPOSTリクエストを送信します: https://graph.facebook.com/{API_VERSION}/{PIXEL_ID}/events?access_token={TOKEN}。このエッジにPOSTリクエストを送信すると、Facebookは新しいサーバーイベントを作成します。

curl -X POST \ -F 'data=[ { "event_name": "Purchase", "event_time": 1715930565, "user_data": { "em": [ "309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd" ], "ph": [ "254aa248acb47dd654ca3ea53f48c2c26d641d23d7e2e93a1ec56258df7674c4", "6f4fcb9deaeadc8f9746ae76d97ce1239e98b404efe5da3ee0b7149740f89ad6" ], "client_ip_address": "123.123.123.123", "client_user_agent": "$CLIENT_USER_AGENT", "fbc": "fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890", "fbp": "fb.1.1558571054389.1098115397" }, "custom_data": { "currency": "usd", "value": 123.45, "contents": [ { "id": "product123", "quantity": 1, "delivery_category": "home_delivery" } ] }, "event_source_url": "http://jaspers-market.com/product/123", "action_source": "website" } ]' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v19.0/<PIXEL_ID>/events
'use strict'; const bizSdk = require('facebook-nodejs-business-sdk'); const Content = bizSdk.Content; const CustomData = bizSdk.CustomData; const DeliveryCategory = bizSdk.DeliveryCategory; const EventRequest = bizSdk.EventRequest; const UserData = bizSdk.UserData; const ServerEvent = bizSdk.ServerEvent; const access_token = '<ACCESS_TOKEN>'; const pixel_id = '<ADS_PIXEL_ID>'; const api = bizSdk.FacebookAdsApi.init(access_token); let current_timestamp = Math.floor(new Date() / 1000); const userData = (new UserData()) .setEmails(['joe@eg.com']) .setPhones(['12345678901', '14251234567']) // It is recommended to send Client IP and User Agent for Conversions API Events. .setClientIpAddress(request.connection.remoteAddress) .setClientUserAgent(request.headers['user-agent']) .setFbp('fb.1.1558571054389.1098115397') .setFbc('fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890'); const content = (new Content()) .setId('product123') .setQuantity(1) .setDeliveryCategory(DeliveryCategory.HOME_DELIVERY); const customData = (new CustomData()) .setContents([content]) .setCurrency('usd') .setValue(123.45); const serverEvent = (new ServerEvent()) .setEventName('Purchase') .setEventTime(current_timestamp) .setUserData(userData) .setCustomData(customData) .setEventSourceUrl('http://jaspers-market.com/product/123') .setActionSource('website'); const eventsData = [serverEvent]; const eventRequest = (new EventRequest(access_token, pixel_id)) .setEvents(eventsData); eventRequest.execute().then( response => { console.log('Response: ', response); }, err => { console.error('Error: ', err); } );
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; use FacebookAds\Object\ServerSide\ActionSource; use FacebookAds\Object\ServerSide\Content; use FacebookAds\Object\ServerSide\CustomData; use FacebookAds\Object\ServerSide\DeliveryCategory; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\EventRequest; use FacebookAds\Object\ServerSide\UserData; $access_token = '<ACCESS_TOKEN>'; $pixel_id = '<ADS_PIXEL_ID>'; $api = Api::init(null, null, $access_token); $api->setLogger(new CurlLogger()); $user_data = (new UserData()) ->setEmails(array('joe@eg.com')) ->setPhones(array('12345678901', '14251234567')) // It is recommended to send Client IP and User Agent for Conversions API Events. ->setClientIpAddress($_SERVER['REMOTE_ADDR']) ->setClientUserAgent($_SERVER['HTTP_USER_AGENT']) ->setFbc('fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890') ->setFbp('fb.1.1558571054389.1098115397'); $content = (new Content()) ->setProductId('product123') ->setQuantity(1) ->setDeliveryCategory(DeliveryCategory::HOME_DELIVERY); $custom_data = (new CustomData()) ->setContents(array($content)) ->setCurrency('usd') ->setValue(123.45); $event = (new Event()) ->setEventName('Purchase') ->setEventTime(time()) ->setEventSourceUrl('http://jaspers-market.com/product/123') ->setUserData($user_data) ->setCustomData($custom_data) ->setActionSource(ActionSource::WEBSITE); $events = array(); array_push($events, $event); $request = (new EventRequest($pixel_id)) ->setEvents($events); $response = $request->execute(); print_r($response);
import time from facebook_business.adobjects.serverside.action_source import ActionSource from facebook_business.adobjects.serverside.content import Content from facebook_business.adobjects.serverside.custom_data import CustomData from facebook_business.adobjects.serverside.delivery_category import DeliveryCategory from facebook_business.adobjects.serverside.event import Event from facebook_business.adobjects.serverside.event_request import EventRequest from facebook_business.adobjects.serverside.user_data import UserData from facebook_business.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' pixel_id = 'ADS_PIXEL_ID>' FacebookAdsApi.init(access_token=access_token) user_data = UserData( emails=['joe@eg.com'], phones=['12345678901', '14251234567'], # It is recommended to send Client IP and User Agent for Conversions API Events. client_ip_address=request.META.get('REMOTE_ADDR'), client_user_agent=request.headers['User-Agent'], fbc='fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890', fbp='fb.1.1558571054389.1098115397', ) content = Content( product_id='product123', quantity=1, delivery_category=DeliveryCategory.HOME_DELIVERY, ) custom_data = CustomData( contents=[content], currency='usd', value=123.45, ) event = Event( event_name='Purchase', event_time=int(time.time()), user_data=user_data, custom_data=custom_data, event_source_url='http://jaspers-market.com/product/123', action_source=ActionSource.WEBSITE, ) events = [event] event_request = EventRequest( events=events, pixel_id=pixel_id, ) event_response = event_request.execute() print(event_response)
import com.facebook.ads.sdk.APIContext; import com.facebook.ads.sdk.APIException; import com.facebook.ads.sdk.serverside.ActionSource; import com.facebook.ads.sdk.serverside.Content; import com.facebook.ads.sdk.serverside.CustomData; import com.facebook.ads.sdk.serverside.DeliveryCategory; import com.facebook.ads.sdk.serverside.Event; import com.facebook.ads.sdk.serverside.EventRequest; import com.facebook.ads.sdk.serverside.EventResponse; import com.facebook.ads.sdk.serverside.UserData; import java.util.Arrays; public class ServerSideApiExample { public static final String ACCESS_TOKEN = "<ACCESS_TOKEN>"; public static final String PIXEL_ID = "<ADS_PIXEL_ID>"; public static void main(String[] args) { APIContext context = new APIContext(ACCESS_TOKEN).enableDebug(true); context.setLogger(System.out); UserData userData = new UserData() .emails(Arrays.asList("joe@eg.com")) .phones(Arrays.asList("12345678901", "14251234567")) // It is recommended to send Client IP and User Agent for Conversions API Events. .clientIpAddress(clientIpAddress) .clientUserAgent(clientUserAgent) .fbc("fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890") .fbp("fb.1.1558571054389.1098115397"); Content content = new Content() .productId("product123") .quantity(1L) .deliveryCategory(DeliveryCategory.home_delivery); CustomData customData = new CustomData() .addContent(content) .currency("usd") .value(123.45F); Event purchaseEvent = new Event(); purchaseEvent.eventName("Purchase") .eventTime(System.currentTimeMillis() / 1000L) .userData(userData) .customData(customData) .eventSourceUrl("http://jaspers-market.com/product/123") .actionSource(ActionSource.website); EventRequest eventRequest = new EventRequest(PIXEL_ID, context); eventRequest.addDataItem(purchaseEvent); try { EventResponse response = eventRequest.execute(); System.out.println(String.format("Standard API response : %s ", response)); } catch (APIException e) { e.printStackTrace(); } } }
require 'facebook_ads' access_token = '<ACCESS_TOKEN>' pixel_id = '<ADS_PIXEL_ID>' FacebookAds.configure do |config| config.access_token = access_token end user_data = FacebookAds::ServerSide::UserData.new( emails: ['joe@eg.com'], phones: ['12345678901', '14251234567'], # It is recommended to send Client IP and User Agent for Conversions API Events. client_ip_address: request.remote_ip, client_user_agent: request.user_agent, fbc: 'fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890', fbp: 'fb.1.1558571054389.1098115397' ) content = FacebookAds::ServerSide::Content.new( product_id: 'product123', quantity: 1, delivery_category: 'home_delivery' ) custom_data = FacebookAds::ServerSide::CustomData.new( contents: [content], currency: 'usd', value: 123.45 ) event = FacebookAds::ServerSide::Event.new( event_name: 'Purchase', event_time: Time.now.to_i, user_data: user_data, custom_data: custom_data, event_source_url: 'http://jaspers-market.com/product/123', action_source: 'website' ) request = FacebookAds::ServerSide::EventRequest.new( pixel_id: pixel_id, events: [event] ) print request.execute

access_tokenクエリパラメーターを使用して、生成された安全なアクセストークンをリクエストに添付します。グラフAPIエクスプローラを使用して、/<pixel_id>/eventsエンドポイントにPOSTすることもできます。

リクエスト本文の例を以下に示します。

{
   "data": [
      {
         "event_name": "Purchase",
         "event_time": 1633552688,
         "event_id": "event.id.123",
         "event_source_url": "http:\/\/jaspers-market.com\/product\/123",         
         "action_source": "website",
         "user_data": {
            "client_ip_address": "192.19.9.9",
            "client_user_agent": "test ua",
            "em": [
               "309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd"
            ],
            "ph": [
               "254aa248acb47dd654ca3ea53f48c2c26d641d23d7e2e93a1ec56258df7674c4",
               "6f4fcb9deaeadc8f9746ae76d97ce1239e98b404efe5da3ee0b7149740f89ad6"
            ],
            "fbc": "fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890",
            "fbp": "fb.1.1558571054389.1098115397"
         },
         "custom_data": {
            "value": 100.2,
            "currency": "USD",
            "content_ids": [
               "product.id.123"
            ],
            "content_type": "product"
         },
         "opt_out": false
      },
      {
         "event_name": "Purchase",
         "event_time": 1633552688,
         "user_data": {
            "client_ip_address": "192.88.9.9",
            "client_user_agent": "test ua2"
         },
         "custom_data": {
            "value": 50.5,
            "currency": "USD"
         },
         "opt_out": false
      }
   ]
}

アップロード時間とイベントトランザクション時間の対比

event_timeはイベントトランザクション時間です。実際のイベントがいつ発生したかを示す秒単位のUNIXタイムスタンプとして送信する必要があります。イベントをFacebookに送信する時間より前の時間を指定することもできます。これは、バッチ処理を行い、サーバーパフォーマンスを最適化するためです。

event_timeには、イベントをMetaに送信する最大7日前の時間を指定できます。dataevent_timeが7日より前である場合、リクエスト全体に対してエラーが返され、イベントは処理されません。physical_storeaction_sourceとしたオフラインと実店舗のイベントの場合は、コンバージョンから62日以内にトランザクションをアップロードしてください。

コンバージョンAPIを使用することで、自分が知る限りaction_sourceパラメーターが正確であることに同意するものとします。

バッチリクエスト

data内で最大1,000件のイベントを送信できます。ただし、パフォーマンスを最適化するには、イベントが発生したらできるだけ早く(できればイベントが発生してから1時間以内に)送信することをおすすめします。バッチで送信したいずれかのイベントが無効であると、バッチ全体が却下されます。

ハッシュ化

顧客情報パラメーターのページで、Facebookに送信する前にどのパラメーターにハッシュ化が必要かをご確認ください。FacebookのいずれかのビジネスSDKを使用している場合、ハッシュ化はSDKによって自動的に行われます。

コンバージョンAPI用のビジネスSDK機能

コンバージョンAPIユーザー向けに特別に設計された3つのビジネスSDK機能をご確認ください: 非同期リクエスト並行バッチ処理HTTPサービスインターフェイス。これらの機能を使うために必要な最低言語バージョンは次のとおりです。

  • PHP >= 7.2
  • Node.js >= 7.6.0
  • Java >= 8
  • Python >= 2.7
  • Ruby >= 2

PHP 5に対するビジネスSDKのサポートは、2019年1月以降廃止されました。ビジネスSDKを使用するには、PHP 7にアップグレードしてください。

PHP 5を使う必要がある場合は、Swagger実装の使用をご検討ください。

コンバージョンAPIのパラメーター

イベントの確認

イベントを送信したら、イベントが受信されたことをイベントマネージャで確認します。

  • [データソース]ページで、POSTリクエストのPIXEL_IDに対応するピクセルをクリックします。詳しくは、ビジネスヘルプセンター: イベントマネージャの概要をご覧ください。
  • 次に、[概要]をクリックします。Facebookが受信した、加工前のイベント、マッチしたイベント、アトリビューションされるイベントの数が表示されます。[接続方法]には、そのイベントが送信されたチャネルが表示されます。
  • 各イベントをクリックすると、詳細な情報を確認できます。
  • イベントの送信の開始後20分以内にイベントを確認できるようになります。これで、サーバーからイベントの送信を開始できるようになりました。

イベントテストツール

イベントマネージャのイベントテスト機能を使用して、サーバーイベントがFacebookにより正しく受信されていることを確認できます。ツールを見つけるには、Events Manager > Data Sources > Your Pixel > Test Eventsにアクセスします。

イベントテストツールはテストIDを生成します。テストIDをtest_event_codeパラメーターとして送信し、[イベントのテスト]ウィンドウにイベントアクティビティが表示されることを確認します。

: test_event_codeフィールドはテスト目的でのみ使うようにしてください。本番ペイロード送信時には削除する必要があります。

test_event_codeを使用して送信したイベントはドロップされません。イベントマネージャに入り、ターゲット設定と広告測定のために使われます。

リクエストを作成する方法の例を次に示します。

{ "data": [ { "event_name": "ViewContent", "event_time": 1715929965, "event_id": "event.id.123", "event_source_url": "http:\/\/jaspers-market.com", "user_data": { "client_ip_address": "1.2.3.4", "client_user_agent": "test user agent" } } ], "test_event_code": "TEST123" }

以下の例は、グラフAPIエクスプローラでリクエストがどのように表示されるかを示しています。

このテストペイロードは、ペイロードヘルパーツールを使用して生成できます。テストイベントコードは、あくまでもペイロードのテスト用のコードです。

リクエストが送信されると、サーバーイベントが[イベントのテスト]ウィンドウに表示されます。

米国のユーザーに適用されるデータ処理オプション

これらの2つのAPIでは、イベントのデータパラメーター内で各イベント内にdata_processing_optionsdata_processing_options_countrydata_processing_options_stateを追加することにより、データ処理オプションを実装します。

注: アプリイベントとオフラインコンバージョンAPIの新規連携は推奨されなくなりました。その代わりに、ウェブ、アプリ、オフラインイベントに対応しているコンバージョンAPIを使用することを推奨します。詳しくは、アプリイベント用コンバージョンAPIオフラインイベント用コンバージョンAPIをご覧ください。

限定データ使用 (LDU)を明示的に有効にしない場合は、各イベントに空の配列を指定するか、単にペイロードのフィールドを削除してください。

{
    "data": [
        {
            "event_name": "Purchase",
            "event_time": <EVENT_TIME>,
            "user_data": {
                "em": "<EMAIL>"
            },
            "custom_data": {
                "currency": "<CURRENCY>",
                "value": "<VALUE>"
            },
            "data_processing_options": []
        }
    ]
}

LDUを有効にしてMetaに地理的位置情報を使用させるには、次のコードを使用します。

{
    "data": [
        {
            "event_name": "Purchase",
            "event_time": <EVENT_TIME>,
            "user_data": {
                "em": "<EMAIL>",
                "client_ip_address": "256.256.256.256"
            },
            "custom_data": {
                "currency": "<CURRENCY>",
                "value": "<VALUE>"
            },
            "data_processing_options": ["LDU"],
            "data_processing_options_country": 0,
            "data_processing_options_state": 0
        }
    ]
}

LDUを有効にしてカリフォルニア州など位置情報を手動で特定するには、次のコードを使用します。

{
    "data": [
        {
            "event_name": "Purchase",
            "event_time": <EVENT_TIME>,
            "user_data": {
                "em": "<EMAIL>"
            },
            "custom_data": {
                "currency": "<CURRENCY>",
                "value": "<VALUE>"
            },
            "data_processing_options": ["LDU"],
            "data_processing_options_country": 1,
            "data_processing_options_state": 1000
        }
    ]
}

手動アップロードUI

オフラインコンバージョンAPIは、.csvファイルからイベントを手動でアップロードするオプションを提供します。その場合は、データ処理オプション、データ処理国、データ処理州をファイル内に列として追加します。詳細については、アップロードのユーザーインターフェイスをご覧ください。


詳しくは、データ処理オプションをご覧ください。

APIの制限

マーケティングAPIには独自のレート制限ロジックがあり、すべてのグラフAPIのレート制限から除外されます。そのため、マーケティングAPI呼び出しを実行しても、グラフAPIのスロットリングの計算には含められません。

コンバージョンAPIには、具体的なレート制限はありません。コンバージョンAPIの呼び出しは、マーケティングAPIの呼び出しとしてカウントされます。唯一の制限は、一度に送信できるイベント数が最大1,000件であることです。詳しくは、リクエストの送信をご覧ください。

マーケティングAPIのレート制限

コンバージョンAPIゲートウェイでのBusiness SDK APIの使用

このガイドでは、コンバージョンAPIゲートウェイユーザー向けに特別に設計されたMeta Business SDKの高度な機能について説明します。コンバージョンAPIゲートウェイの基本的な使用方法については、コンバージョンAPIゲートウェイのドキュメントを参照してください。

イベントをコンバージョンAPIゲートウェイインスタンスに送る

要件

下記の機能のいずれかを使用するには、Meta Business SDKをインストールしておかなければなりません。Meta Business SDKのスタートガイドをご覧になるか、こちらにリストされているREADMEの指示に従ってください。

現在、これらの機能はPHPとJavaビジネスSDKでのみ利用可能です。その他の言語は2023年末までに実装される予定です。

これらの機能を使うために必要な各言語の最低バージョンは次のとおりです。

PHP >= 7.2

Java >= 8

: コンバージョンAPIエンドポイントに送るイベントの重複を排除するため、リクエストでeventIdを渡してください。これにより、コンバージョンAPIの公開が有効になっている場合に、重複イベントが表示されるのを防ぐことができます。

CAPIGatewayIngressRequestパラメーターのフォーマット

パラメーター説明
endpointUrl
文字列

イベント送信先のコンバージョンAPIゲートウェイエンドポイント。パラメーターに対して、有効なURLの確認以外の事前検証は行われません。


例: https://test.example.com


accessKey
文字列

コンバージョンAPIゲートウェイのイベントエンドポイントにイベントを送信するために必要なコンバージョンAPIゲートウェイのアクセスキー。アクセスキーを生成するための手順をご覧ください。

CAPIGatewayIngressRequestセッター

パラメーター説明
setSendToDestinationOnly
ブーリアン

選択されたエンドポイントにのみイベントを送信するかどうかについてのブーリアンフラグ。


デフォルト: False


setFilter
CustomEndpointRequest.Filter()関数

各イベントを処理するフィルター関数。フィルタリングロジックがtrueを返すと、イベントは通過します。そうでない場合は、イベントがドロップされます。Eventパラメーターを持つインターフェイスにshouldSendEvent関数を実装する必要があります。


デフォルト: Null



移行例: PHP

すでにBusiness SDKを使用しているシステムの場合、新しいCAPIGatewayIngressRequestを参照し、それをeventRequestのcustomEndpointオブジェクトにアタッチするだけです。

// this is the standard event request that we attach events to
$event_request = new EventRequest($this->pixel_id);
$capiIngressRequest = new CAPIGatewayIngressRequest($this->cb_url, $this->access_key);
$event_request->setCustomEndpoint($capiIngressRequest);
// pass the events to this event Request object
$event_request->setEvents($events);
$event_request->execute()

移行例: Java

すでにBusiness SDKを使用しているシステムの場合、新しいCAPIGatewayIngressRequestを参照し、それをeventRequestのcustomEndpointオブジェクトにアタッチするだけです。

// this is the standard event request that we attach events to


EventRequest eventRequest = new EventRequest(PIXEL_ID, context);


CAPIGatewayIngressRequest capiSyncRequest = new CAPIGatewayIngressRequest(CB_URL, CAPIG_ACCESS_KEY);
eventRequest.setCustomEndpoint(capiSyncRequest);
eventRequest.addDataItem(testEvent);
eventRequest.execute();

同期オプション

PHPのコード例

$api = Api::init(null, null, $this->access_token);
$api->setLogger(new CurlLogger());
$event_request = new EventRequest($this->pixel_id);
$capiIngressRequest = new CAPIGatewayIngressRequest($this->cb_url, $this->access_key);
$event_request->setCustomEndpoint($capiIngressRequest);
$user_data = (new UserData())
   ->setEmails(array('joe@eg.com'))
   ->setPhones(array('12345678901', '14251234567'))
   ->setFbc('fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890')
   ->setFbp('fb.1.1558571054389.1098115397');
$event1 = (new Event())
   ->setEventName('Purchase')
   ->setEventId('125')
   ->setEventTime(time())
   ->setEventSourceUrl('http://jaspers-market.com/product/123')
   ->setUserData($user_data);
$events = array($event1, $event2);
$event_request->setEvents($events);
$response = $event_request->execute();
print($response->__toString());

Javaのコード例

EventRequest eventRequest = new EventRequest(PIXEL_ID, context);
UserData userData = new UserData()
       .email("abc@eg.com");
CAPIGatewayIngressRequest capiSyncRequest = new CAPIGatewayIngressRequest(CB_URL, CAPIG_ACCESS_KEY);
eventRequest.setCustomEndpoint(capiSyncRequest);
Event testEvent = new Event();
testEvent.eventId("125").eventName("Purchase")
       .eventTime(System.currentTimeMillis() / 1000L)
       .userData(userData)
       .dataProcessingOptions(new String[]{}).setEventId("134423232");
eventRequest.namespaceId("11")
       .uploadId("22222")
       .uploadTag("upload-tag-4")
       .uploadSource("upload-source-4")
       .testEventCode("test-event-code-5")
       .partnerAgent("partner-agent-6");
eventRequest.addDataItem(testEvent);
eventRequest.execute();

非同期オプション

PHPのコード例

$api = Api::init(null, null, $this->access_token);
$api->setLogger(new CurlLogger());
$event_request = new EventRequestAsync($this->pixel_id);
$capiIngressRequest = new CAPIGatewayIngressRequest($this->cb_url, $this->access_key);
$capiIngressRequest->setSendToDestinationOnly(true);
$event_request->setCustomEndpoint($capiIngressRequest);
$event1 = (new Event())
   ->setEventName('test Async Event')
   ->setEventId('134423232')
   ->setEventTime(time())
   ->setEventSourceUrl('http://jaspers-market.com/product/123');
$events = array($event1, $event2);
$event_request->setEvents($events);
$response = $event_request->execute()->wait();

Javaのコード例

EventRequest eventRequest = new EventRequest(PIXEL_ID, context);
UserData userData = new UserData()
       .email("abc@eg.com");
CAPIGatewayIngressRequest capiSyncRequest = new CAPIGatewayIngressRequest(CB_URL, CAPIG_ACCESS_KEY);
capiSyncRequest.setSendToDestinationOnly(true);
eventRequest.setCustomEndpoint(capiSyncRequest);
Event testEvent = new Event();
testEvent.eventName("test Async Event")
       .eventTime(System.currentTimeMillis() / 1000L)
       .userData(userData)
       .dataProcessingOptions(new String[]{}).setEventId("134423232");
eventRequest.namespaceId("11222")
       .uploadId("22222")
       .uploadTag("upload-tag-4")
       .uploadSource("upload-source-4")
       .testEventCode("test-event-code-5")
       .partnerAgent("partner-agent-6");
eventRequest.addDataItem(testEvent);
eventRequest.executeAsync();

フィルター機能

PHPのコード例

lass APIFilter implements Filter {
   public function shouldSendEvent(Event $event): bool
   {
       if ($event->getEventId() === '125') {
           return false;
       }
       return true;
   }
}
$capiIngressRequest = new CAPIGatewayIngressRequest($this->cb_url, $this->access_key);
$event_request->setCustomEndpoint($capiIngressRequest);
$capiIngressRequest->setFilter(new APIFilter());

Javaのコード例

CAPIGatewayIngressRequest capiSyncRequest = new CAPIGatewayIngressRequest(CB_URL, CAPIG_ACCESS_KEY);
eventRequest.setCustomEndpoint(capiSyncRequest);


capiSyncRequest.setFilter(new CustomEndpointRequest.Filter() {
   @Override
   public boolean shouldSendEvent(Event event) {
   if (event.getEventId().equals("125")) {
       return true;
   }
   return false;
}
});