Facebook Retargeting Pixel Code for React Native

Hi I'm trying to add a facebook intercept pixel for my responsive native app and I hope the community can help me clarify something. First, to track an event PageView

or ViewContent

product, I add the following script to the product page.

<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','//connect.facebook.net/en_US/fbevents.js');

fbq('init', 'xxxxxxxxxxxxxxxx');
fbq('track', 'PageView');
fbq('track', 'ViewContent', {

        content_name: 'Truyện Cổ Grimm (Bìa Cứng)',
        content_category: 'Truyện đọc',
        content_ids: ['8935212329736'],
        content_type: 'product',
        value: 153750,
        currency: 'VND'

});
</script>

      

I wonder how I can achieve the same result with React Native. I saw that Facebook has FB SDK for reacting native language ( https://developers.facebook.com/docs/react-native ) and I want to ask if this SDK is something that I can achieve similar to what I have for the web above. What if I view the product, I just do it?

AppEventsLogger.logEvent('ViewContent');

      

If so, can I specify other parameters, maybe so?

AppEventsLogger.logEvent('ViewContent', {

    content_name: 'Truyện Cổ Grimm (Bìa Cứng)',
    content_category: 'Truyện đọc',
    content_ids: ['8935212329736'],
    content_type: 'product',
    value: 153750,
    currency: 'VND'
});

      

Anyone with experience with this successfully please help me. Many thanks

+3


source to share


1 answer


You were right to guess the event to be used with react-native-fbsdk

. If you look at the source of this SDK here , you will see that you can use the method in a logEvent

variety of ways.

Method you guessed it:

AppEventsLogger.logEvent('ViewContent', {
    content_name: 'Truyện Cổ Grimm (Bìa Cứng)',
    content_category: 'Truyện đọc',
    content_ids: ['8935212329736'],
    content_type: 'product',
    value: 153750,
    currency: 'VND'
});

      

The event will be logged in FB Analytics and then you can customize your reports based on these parameters. During my experience with it, I ran into one problem that it doesn't support arrays. Therefore, the above code will be modified as follows:



AppEventsLogger.logEvent('ViewContent', {
    content_name: 'Truyện Cổ Grimm (Bìa Cứng)',
    content_category: 'Truyện đọc',
    content_ids: '8935212329736',
    content_type: 'product',
    value: 153750,
    currency: 'VND'
});

      

With that, you should be good to go. Hope this solved your request.

Note:

Arrays are not supported by React Native Bridge right now. You can check this one for a place where arrays are not supported.

+5


source







All Articles