facebook / facebook-java-business-sdk

Java SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
402 stars 332 forks source link

Sending App conversion data is not possible #413

Closed rominaGYG closed 1 year ago

rominaGYG commented 1 year ago

Which SDK version are you using?

16.0.0

What's the issue?

Based on this documentation we should be able to send app data when the action source is set to "app". However, there is no way to do it currently using SDK. Event class here does not expect any app_data field.

Steps/Sample code to reproduce the issue

Observed Results:

To demonstrate more, using playground, if the action_source is set to app, the code generation for Java (and other Languages) looks like this: expected result :

{
    "data": [
        {
            "event_name": "Purchase",
            "event_time": 1676903018,
            "action_source": "app",
            "user_data": {
                "em": [
                    "7b17fb0bd173f625b58636fb796407c22b3d16fc78302d79f0fd30c2fc2fc068"
                ],
                "ph": [
                    null
                ]
            },
            "custom_data": {
                "currency": "USD",
                "value": "142.52"
            },
            "app_data": {
                "advertiser_tracking_enabled": "True",
                "application_tracking_enabled": "True",
                "extinfo": [
                    "a2",
                    "com.some.app",
                    "771",
                    "Version 7.7.1",
                    "10.1.1",
                    "OnePlus6",
                    "en_US",
                    "GMT-1",
                    "TMobile",
                    "1920",
                    "1080",
                    "2.00",
                    "2",
                    "128",
                    "8",
                    "USA/New York"
                ]
            }
        }
    ]
}

generated code :

import com.facebook.ads.sdk.APIContext;
import com.facebook.ads.sdk.APIException;
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.GenderEnum;
import com.facebook.ads.sdk.serverside.UserData;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class ConversionsApiExample {

  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);
    List<Event> events = new ArrayList<>();

    UserData userData_0 = new UserData()
      .emails(Arrays.asList("7b17fb0bd173f625b58636fb796407c22b3d16fc78302d79f0fd30c2fc2fc068"))
      .phones(Arrays.asList());

    CustomData customData_0 = new CustomData()
      .value(142.52f)
      .currency("USD");

    Event event_0 = new Event()
      .eventName("Purchase")
      .eventTime(1676903018L)
      .userData(userData_0)
      .customData(customData_0)
      .actionSource("app");
    events.add(event_0);

    EventRequest eventRequest = new EventRequest(PIXEL_ID, context)
      .data(events);

    try {
      EventResponse response = eventRequest.execute();
      System.out.printf("Standard API response : %s ", response);
    } catch (APIException e) {
      e.printStackTrace();
    }
  }
}

nowhere in the code is referenced to app_data generation part.

Expected Results:

implementation of app_data in java sdk

stcheng commented 1 year ago

@rominaGYG thanks for reporting this. the team is working on this and will have this issue addressed very soon.

stcheng commented 1 year ago

resolved with the latest update