Meta Pixel Integration: Function for sending events

“Meta pixel integration” refers to the process of integrating and utilizing the Meta Pixel (formerly known as Facebook Pixel) with other platforms or websites outside of Meta’s (Facebook’s) ecosystem.

The Meta Pixel tracks various user interactions on a website or app, such as page views, clicks on specific elements, form submissions, and purchases. This data helps advertisers understand user behavior and measure the performance of their advertising campaigns.

The following function can be used for tracking event data

        sendEventData: function (data) {

            nlapiLogExecution(‘Error’, ‘FB PixelsendEventData ‘, ‘Received data: ‘ + data);

            var apiResponse = null;

            try {

                var token = Configuration.get(‘FbPixel.Token’);

                var facebookPixelId = Configuration.get(‘FbPixel.ID’);

                var url = ‘https://graph.facebook.com/v20.0/’ + facebookPixelId + ‘/events?access_token=’ + token;

                var bodyObj = data;

                var headers = {

                    ‘Content-Type’: ‘application/json’,

                    ‘Accept’: ‘*/*’,

                    ‘Accept-Encoding’: ‘gzip, deflate, br’,

                    ‘Connection’: ‘keep-alive’

                };

                apiResponse = nlapiRequestURL(url, data, headers, ‘POST’);

                nlapiLogExecution(‘Error’, ‘FB Pixel apiResponse’, ‘apiResponse: ‘ + JSON.stringify(apiResponse));

                return apiResponse.getBody();

            } catch (err) {

                return apiResponse;

            }

        }

where

facebookPixelId – Meta pixeid

token :Token generated from event manager

Leave a comment

Your email address will not be published. Required fields are marked *