Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send multiple content_ids? #40

Closed
rukmanary opened this issue May 24, 2021 · 6 comments
Closed

How to send multiple content_ids? #40

rukmanary opened this issue May 24, 2021 · 6 comments
Labels
question Further information is requested

Comments

@rukmanary
Copy link

🐛 Bug Report

I check in node_modules/react-native-fbsdk-next/types/FBAppEventsLogger.d.ts that AppEventParam can only send a single ContentID as a String
Screen Shot 2021-05-24 at 12 00 55

I want to use Dynamic Ads... According to this https://business.facebook.com/business/help/606577526529702?id=1205376682832142 I need to send content_ids which can be a single content ID or an array of content IDs
Screen Shot 2021-05-24 at 12 04 32

And the problem is I can never send an array at all. I use Test Events in Pixels Event Manager to get realtime log. Every time I send an array, VIewItem Event or any other events is not logged.

This picture shows the wrong format. So, JSON.stringify is not a workaround for this.

Screen Shot 2021-05-24 at 13 54 14

To Reproduce

  1. Open Event Manager => Test Events. Make sure the device is connected to this feature
  2. Log ViewItem Event or other Events by sending an array, you can use custom events. Example: product_ids: ['1', '2', '3']
  3. Check Test Events, nothing entered here

Expected Behavior

This library can send an array data type

Environment

"react": "16.9.0",
"react-native": "0.61.1",
"react-native-fbsdk-next": "^4.2.0",

@mikehardy
Copy link
Collaborator

Interesting. So how did it go when you built the string yourself with the correct single-quotes etc then sent that in as the string argument for ContentId?

@rukmanary
Copy link
Author

rukmanary commented May 25, 2021

Well, I will tell you more details...

I tried something like this:

const content_ids = [];
content_ids.push(`${itemCartList[i]?.product_id}`);

const ids = `[${content_ids.join(',')}]`;

AppEventsLogger.logEvent('InitiatedCheckout', 10000, {
      [AppEventsLogger.AppEventParams.ContentID]: ids,
      [AppEventsLogger.AppEventParams.ContentType]: 'product',
      [AppEventsLogger.AppEventParams.Currency]: 'IDR',
      [AppEventsLogger.AppEventParams.NumItems]: parseInt(2),
      [AppEventsLogger.AppEventParams.Content]: JSON.stringify(// * some items' information (array) * // ),
})

it does logged in Test Events because ids is a String. But it takes some times, maybe a day or more to see the result in Catalog Conversions

I track the code and found that the Facebook Android SDK (AppEvent.java) is throwing an exception for datatypes other than String and Number:

Screen Shot 2021-05-25 at 15 16 53

as mentioned here https://developers.facebook.com/docs/app-events/getting-started-app-events-android

Screen Shot 2021-05-25 at 15 23 55

Honestly, I'm a little bit confuse with the documentation. It says here https://www.facebook.com/business/help/892811264497819 that the required app events for Dynamic Ads are:
Screen Shot 2021-05-25 at 15 33 58

My app can purchased more than one item at once, so it has multiple contentID. But, the SDK is not allowing us to send an array.

In Facebook Commerce Manager, my Retargeted Ads is 0%:
Screen Shot 2021-05-25 at 15 37 34

In How to Fix it section, I just did the number one solution and waiting for the result for single contentID.
I click Learn More and this appears:
Screen Shot 2021-05-25 at 15 47 35

I already make sure everything in the screenshot above. Now I scroll down and come to this part:

Screen Shot 2021-05-25 at 15 48 02

or you can read it from this https://business.facebook.com/business/help/644889989181423?id=725943027795860 it's exactly the same.

It said "website", now I may change the question, is multiple contentID only possible for website (for now)? Because the article said that we need to send content_ids with 's'. And it can be String or Array data type. But, technically, in mobile apps we cannot send an array.

@mikehardy
Copy link
Collaborator

const ids = [${content_ids.join(',')}];

Should maybe be

const ids = ['${content_ids.join('','')}'];

(note the single-quotes - to match what they request, I think)

Honestly this is way out of my depth, but it still seems like the content ids are not sent exactly as they expect, with each id being a number inside single quotes, with multiple ids separated by commas

@thebergamo thebergamo added the question Further information is requested label May 27, 2021
@rukmanary
Copy link
Author

I already done that. But it turns out even a single id doesn't match too. I already follow the instruction in this library, Event Manager received all of my events. I also made some catalog, input the products and write down the content ID the same value as I sent from events. But when it comes to the Commerce Manager, Mobile App Conversions with Matched Content IDs shows me 0% matches to contentID.

I can't figure out what's wrong because l just follow the instruction to initializedSDK and then we good to go. I just need AppEvent feature for Fb Pixel and from this example https://github.com/thebergamo/react-native-fbsdk-next#app-events-1 there's no other setup. So, I don't know what's wrong?

Do you have any reference or can you confirm that this is only happens to me and the others app works fine?

@mikehardy
Copy link
Collaborator

This is not a use case for me so I have never coded to these APIs or used them and am not planning too - which means unfortunately I think I've helped you as much as I can

@rukmanary
Copy link
Author

Anyway, I solved this recently... As I mention above, I send the event like this:

const content_ids = [];
content_ids.push(`${itemCartList[i]?.product_id}`);

const ids = `[${content_ids.join(',')}]`;

AppEventsLogger.logEvent('InitiatedCheckout', 10000, {
      [AppEventsLogger.AppEventParams.ContentID]: ids,
      [AppEventsLogger.AppEventParams.ContentType]: 'product',
      [AppEventsLogger.AppEventParams.Currency]: 'IDR',
      [AppEventsLogger.AppEventParams.NumItems]: parseInt(2),
      [AppEventsLogger.AppEventParams.Content]: JSON.stringify(// * some items' information (array) * // ),
      // some custom params
})

But then I tried to send a minimum parameters as the facebook documentation said and modify my code:

    const content_ids = [];
    content_ids.push(`${itemCartList[i]?.product_id}`);
    const ids = content_ids?.length > 1
                   ? `[${content_ids.join(',')}]`
                   : content_ids[0];

AppEventsLogger.logEvent('InitiatedCheckout', 10000, {
      [AppEventsLogger.AppEventParams.ContentID]: ids,
      [AppEventsLogger.AppEventParams.ContentType]: 'product',
      [AppEventsLogger.AppEventParams.Currency]: 'IDR',
      [AppEventsLogger.AppEventParams.NumItems]: parseInt(2),
})

And it finally works, the data now can be retargeted.

I have 2 suspects, but I don't have any prove yet:

  1. Dynamic Ads Event cannot take custom params
  2. Double quote in JSON.stringify output

But I guess suspect number 2 is the real problem since they mention in the documentation to send contentID in single quote. But what makes me confuse is the documentation give me an example how to write AppEventsLogger.AppEventParams.Content param as a JSON. So I simply use JSON.stringify...
Screen Shot 2021-06-28 at 11 17 27

In conclusion, the solution for me to send single or multiple contentID for Dynamic Ads for Mobile Apps is to send a minimum parameters just like the example in documentation. For my case in retail/e-Commerce, I follow this: https://developers.facebook.com/docs/app-events/best-practices/ecom-and-retail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants