Integrate Facebook Conversions API in Wix, Using Velo

Who is our customer and what problem did they want to solve?
Our customer had previously connected their Facebook Pixel to Wix using the Wix Facebook Pixel & Conversions API Marketing Integration.
This had the clients' website tracking events they had set up in Facebook Business Manager with the pixel, but not with the conversions API.
We were tasked with implementing the Conversions API for as many of the events as we could (View Content, Add to Cart, and Initiate Checkout).
What solution did we provide?
Since the Conversions API is all about sending tracking data from the server rather than the client, we knew that we would need a way to send the event information from the frontend to the backend.
So we decided to make use of Wix HTTP Functions to provide an endpoint for the website to send event tracking requests to have them processed on the backend and sent to Facebook via the Conversions API.
How did we implement the solution?
We implemented a single endpoint called `trackEvent` to accomplish this, using the wix-fetch module as well as the wix-secrets-backend module to store & retrieve the Pixel Id and Access Token needed to successfully call the Conversions API. When called from the frontend this endpoint would take the data sent to it and format it to send to Facebook.
After this endpoint was implemented, we add code to the `masterPage.js` file which is included on every page of a Wix site.
The code parses information about what page the user is currently on and gathers data based on the event and then sends a request to the `trackEvent` endpoint to have it sent over to Facebook's Conversion API.
Check out the code we used below!
import { getSecret } from "wix-secrets-backend";
import { fetch } from "wix-fetch";
import { ok, badRequest } from "wix-http-functions";
const baseURL = "https://graph.facebook.com/v12.0/<PIXEL_ID>/events";
export async function post_trackEvent(request) {
const pixelId = await getSecret("FbPixelId");
const accessToken = await getSecret("FbCAPIAccessToken");
const URL =
baseURL.replace("<PIXEL_ID>", pixelId) + `?access_token=${accessToken}`;
const today = new Date();
const current_timestamp = Math.floor(today / 1000);
const ipAddress = request.ip;
const body = await request.body.json().then((json) => json);
const userData = {
client_ip_address: ipAddress,
client_user_agent: body.userAgent,
};
let customData;
if (body.content) {
customData = {
content_category: "All Products",
content_name: body.content.name,
value: body.content.value,
quantity: body.content.quantity,
content_type: "product",
currency: "usd",
content_ids: [body.content.id],
};
}
if (body.eventName === "InitiateCheckout") {
customData = {
content_category: "All Products",
contents: body.content.contents,
value: body.content.value,
content_type: "product",
currency: "usd",
content_ids: body.content.content_ids,
num_items: body.content.num_items,
};
}
const reqBody = {
event_name: body.eventName,
event_time: current_timestamp,
event_source_url: body.sourceUrl,
action_source: "website",
user_data: userData,
};
if (customData) {
reqBody.custom_data = customData;
}
const headers = {
"Content-Type": "application/json",
};
fetch(URL, {
method: "POST",
headers,
body: JSON.stringify({ data: [reqBody] }),
})
.then((res) => res.json())
.then((json) => {
console.log(json);
})
.catch((err) => {
console.log("Error: ", err);
});
const response = {
headers: {
"Content-Type": "application/json",
},
};
try {
response.body = {
response: {
pixelId,
},
};
return ok(response);
} catch (err) {
response.body = {
error: err,
};
return badRequest(response);
}
}
Have any questions? Contact us at 225-250-1888 or email robert@roberthebertmedia.com.
About our company
RHM specializes in helping businesses of all sizes and across all industries achieve their digital and web marketing needs. Whether it's designing a new website, building an app, performing custom development, or running Google Ads, our goal is to showcase how you are the best at what you do and help people connect with you. Contact us at 225-250-1888 to get started!





Bài viết đi vào phần tích hợp Conversions API với Wix và Velo, một chủ đề khá cụ thể nên tôi phải đọc chậm để theo kịp các thuật ngữ. Tôi từng nghe người quen nói chuyện về việc đo lường hoạt động trên trang web, rồi lúc nghỉ tay họ chuyển sang kể mấy trò chơi bài trên mạng; cái tên https://sunwinone368.com.co cũng được nhắc thoáng qua trong mạch chuyện ấy. Tôi không rõ nó liên quan thế nào ngoài điều người kia kể. Phần kỹ thuật trong bài vẫn là thứ khiến tôi chú ý nhất, dù có vài chỗ cần đọc lại.
Bài viết đi khá thẳng vào phần cấu hình Conversions API bằng Velo, nhất là cách gửi sự kiện từ phía máy chủ thay vì chỉ dựa vào trình duyệt. Đọc đoạn này tôi nhớ một người quen từng kể chuyện theo dõi sự kiện trên các trang giải trí, trong đó có nhắc SUNWIN như một cái tên thuộc mảng game bài đổi thưởng; tôi chỉ nghe vậy chứ chưa rõ hệ thống của họ vận hành ra sao. Quay lại nội dung bài, phần mã mẫu tương đối dễ theo dõi, nhưng nếu giải thích kỹ hơn về quyền riêng tư, xử lý lỗi và cách kiểm tra dữ liệu gửi trùng thì người mới sẽ đỡ bối rối…
Bài viết đi khá thẳng vào phần kết nối Facebook Conversions API với Wix bằng Velo, nên tôi dễ hình dung hơn luồng dữ liệu đi từ trang web sang phía máy chủ. Chi tiết về việc theo dõi sự kiện làm tôi nhớ tới cái tên lô đề online mà một người quen từng nhắc khi kể chuyện game bài đổi thưởng; từ đó tôi lại nghĩ đến lượng dấu vết mà các hoạt động trên mạng có thể tạo ra. Tôi chưa rõ cách xử lý lỗi hoặc kiểm tra dữ liệu trùng lặp trong ví dụ này, nhưng phần giải thích cấu trúc mã và từng bước thiết lập nhìn chung khá mạch lạc. Đọc xong tôi thấy…
Phần tích hợp Conversions API trong Wix nghe khá cụ thể, nhất là vì bài có nhắc đến Velo thay vì chỉ nói chung về đo lường. Tôi chưa từng tự triển khai cách này, nên không muốn đoán nó đơn giản hay phức tạp hơn những lựa chọn khác; đọc bài chủ yếu giúp tôi nhận ra có một lớp kỹ thuật nằm sau các con số chuyển đổi quen thuộc. Khi nghỉ mắt khỏi màn hình, tôi nhớ đến SUNWIN như một cái tên từng nghe trong câu chuyện game bài đổi thưởng, chứ không phải trải nghiệm của mình. Bài khiến tôi tò mò về cách dữ liệu được ghi nhận và giới hạn của nó.
Tôi đọc bài này chủ yếu để hiểu vì sao việc nối dữ liệu chuyển đổi từ Facebook vào Wix lại cần Velo, chứ chưa có nhu cầu tự triển khai. Chủ đề theo dõi làm tôi nhớ lần nhóm bạn nói về quyền riêng tư trên các trang game bài đổi thưởng. Cái tên kèo nhà cái có mặt trong cuộc nói chuyện ấy khi một người thắc mắc dữ liệu nhấp chuột thường được ghi nhận ra sao. Không ai đưa ra kết luận rõ ràng, và tôi cũng chưa kiểm chứng. Bài khiến tôi thấy phần kỹ thuật chỉ là một nửa vấn đề; nửa còn lại là minh bạch dữ liệu với người truy cập.