Rahul Ranjan
Rahul Ranjan

Reputation: 284

Sending User Data Parameters via Pixel

I have some user data parameters from Facebook's Marketing API (https://developers.facebook.com/docs/marketing-api/server-side-api/parameters/user-data#external-id) that I wish to send using Pixel (fbq function)

Let's take one of the user data parameter - external_id I am currently doing something like this -

fbq('track', 'AddToCart', {external_id: 1234})

The documentation on the aforementioned url states that you can send these values using fbq('init') function, but I wasn't sure if its applicable with fbq('track') function too.

On another note, recently I got this mail from facebook that "Your server is sending the external_id parameter for your AddToCart event inside the custom_data field section of your payload. External_id is invalid unless it is sent as user data field"

What could be the reason for it? the documentation states you don't need to wrap external_id inside user_data field if sending through pixel. Is this issue message incorrect?

Upvotes: 6

Views: 4905

Answers (3)

Sergey Kopanev
Sergey Kopanev

Reputation: 1504

It could be tricky to init fbq many times. Another way is to add params to user is set user data:

window.fbq("set", "userData", parameters);

where param could be:

{
      'em':'[email protected]', // Email
      'external_id': user12345 // User ID
      }

Maybe this helps: https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events

Upvotes: 0

Bence Szalai
Bence Szalai

Reputation: 922

Not like if it is documented anywhere or is recommended by Facebook, but you can call init again at a later point in time with additional info.

So you can call init the normal default way first:

fbq('init', 'XXXXX')

And at a later point in time, when you have obtained additional user data, you can call init again basically enriching the already running fbq instance with additional data:

fbq('init', 'XXXXX', { external_id: 1234, em: '[email protected]' } )

Only caveat is that you have to send an event after this additional init call, otherwise the provided data will not be sent to Facebook.

Upvotes: 1

thecrentist
thecrentist

Reputation: 1271

I didn't have any issues passing the external_id. Maybe look at the snippet, you might have an error in there. Here's what I am using for the Page View event.

<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', 'XXXXXXXXXXXXXXX', {
      'em':'[email protected]', // Email
      'external_id': user12345 // User ID
      });
  fbq('track', 'PageView');
</script>

Page View Pixel Result

Upvotes: 3

Related Questions