Trình Kết Nối Meta Ads

Kết nối Meta Ads (Facebook & Instagram) với Brevo qua Tajo để đồng bộ Custom Audiences, import conversion events qua Conversions API và kết nối paid social advertising với lifecycle marketing automation.

Tổng Quan

Thuộc TínhGiá Trị
Nền TảngMeta Ads (Facebook, Instagram, Messenger, WhatsApp)
Danh MụcMarketing
Độ Phức Tạp Thiết LậpNâng Cao
Tích Hợp Chính ThứcKhông
Dữ Liệu Đồng BộAudiences, Conversions, Campaigns, Leads
Skills Có Sẵn8
Phiên Bản APIv25.0 (Graph API)

Tính Năng

  • Đồng bộ Custom Audience - Upload danh sách contacts Brevo như Meta Custom Audiences
  • Conversions API (CAPI) - Gửi server-side conversion events để attribution chính xác
  • Đồng bộ lead form - Import Facebook Lead Ads submissions trực tiếp vào contacts Brevo
  • Campaign insights - Kéo số liệu hiệu suất quảng cáo vào Tajo dashboards
  • Lookalike audiences - Tạo Lookalike Audiences từ Brevo segments đã đồng bộ
  • Đồng bộ catalog - Đồng bộ product catalogs cho dynamic product ads
  • Đa nền tảng - Một tích hợp bao gồm Facebook, Instagram, Messenger và WhatsApp ads

Yêu Cầu

Trước khi bắt đầu, hãy đảm bảo bạn có:

  1. Tài khoản Meta Business Manager
  2. Facebook App với Marketing API access
  3. System User với quyền phù hợp
  4. Access Token với quyền ads_managementads_read
  5. Tài khoản Brevo với quyền truy cập API
  6. Tài khoản Tajo với API credentials

Xác Thực

System User Access Token

Meta khuyến nghị sử dụng System User tokens cho server-to-server integrations. Các tokens này không hết hạn.

Terminal window
# Quyền cần thiết cho System User
ads_management
ads_read
business_management
leads_retrieval
pages_read_engagement
catalog_management

App-Level Authentication

Terminal window
curl -G "https://graph.facebook.com/v25.0/act_AD_ACCOUNT_ID/campaigns" \
-d "access_token=SYSTEM_USER_ACCESS_TOKEN" \
-d "fields=name,status,objective"

Cấu Hình

Thiết Lập Cơ Bản

connectors:
meta_ads:
enabled: true
app_id: "your-facebook-app-id"
app_secret: "your-facebook-app-secret"
access_token: "your-system-user-access-token"
ad_account_id: "act_123456789"
business_id: "987654321"
pixel_id: "111222333444"
# Tùy chọn đồng bộ dữ liệu
sync:
custom_audiences: true
conversions_api: true
lead_forms: true
campaign_insights: true
# Phiên bản API
api_version: "v25.0"

Cấu Hình Custom Audience

Đồng bộ danh sách Brevo sang Meta Custom Audiences:

custom_audiences:
enabled: true
lists:
- brevo_list_id: 5
audience_name: "Tất Cả Khách Hàng"
subtype: "CUSTOM"
- brevo_list_id: 6
audience_name: "Khách Hàng LTV Cao"
subtype: "CUSTOM"
- brevo_list_id: 7
audience_name: "Người Mua Gần Đây"
subtype: "CUSTOM"
# Trường matching
match_keys:
- EMAIL
- PHONE
- FN # Tên
- LN # Họ
- CT # Thành phố
- ST # Bang/Tỉnh
- ZIP
- COUNTRY
schedule: "daily"
sync_mode: "mirror"

Cấu Hình Conversions API

conversions_api:
enabled: true
pixel_id: "111222333444"
test_event_code: "" # Đặt để test, để trống cho production
events:
- brevo_event: "order_completed"
meta_event: "Purchase"
value_field: "revenue"
currency_field: "currency"
- brevo_event: "cart_updated"
meta_event: "AddToCart"
- brevo_event: "customer_created"
meta_event: "Lead"
- brevo_event: "page_viewed"
meta_event: "ViewContent"

API Endpoints

Phương ThứcEndpointMô Tả
POST/v25.0/act_{id}/customaudiencesTạo Custom Audience
POST/v25.0/{audience_id}/usersThêm users vào Custom Audience
DELETE/v25.0/{audience_id}/usersXóa users khỏi Custom Audience
POST/v25.0/{pixel_id}/eventsGửi Conversions API events
GET/v25.0/act_{id}/campaignsLiệt kê campaigns
GET/v25.0/act_{id}/insightsLấy campaign insights
GET/v25.0/{form_id}/leadsLấy lead form submissions
POST/v25.0/act_{id}/adcreativesTạo ad creatives
GET/v25.0/{catalog_id}/productsLiệt kê catalog products

Ví Dụ Code

Khởi Tạo Trình Kết Nối Meta Ads

import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({
apiKey: process.env.TAJO_API_KEY,
brevoApiKey: process.env.BREVO_API_KEY
});
// Kết nối tài khoản Meta Ads
await tajo.connectors.connect('meta-ads', {
appId: process.env.META_APP_ID,
appSecret: process.env.META_APP_SECRET,
accessToken: process.env.META_ACCESS_TOKEN,
adAccountId: 'act_123456789',
pixelId: '111222333444'
});

Gửi Conversions API Events

// Gửi purchase event qua Conversions API
const response = await fetch(
`https://graph.facebook.com/v25.0/${PIXEL_ID}/events`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
data: [{
event_name: 'Purchase',
event_time: Math.floor(Date.now() / 1000),
action_source: 'website',
user_data: {
em: [hashSHA256('[email protected]')],
ph: [hashSHA256('+15551234567')],
fn: [hashSHA256('jane')],
ln: [hashSHA256('kim')],
client_ip_address: '192.168.1.1',
client_user_agent: 'Mozilla/5.0...',
fbc: 'fb.1.1234567890.AbCdEfG', // Click ID
fbp: 'fb.1.1234567890.987654321' // Browser ID
},
custom_data: {
value: 89.99,
currency: 'USD',
content_ids: ['SKU-001'],
content_type: 'product'
}
}],
access_token: process.env.META_ACCESS_TOKEN
})
}
);

Đồng Bộ Custom Audience Từ Danh Sách Brevo

// Upload danh sách contacts Brevo như Meta Custom Audience
await tajo.connectors.syncAudience('meta-ads', {
brevoListId: 5,
audienceName: 'Khách Hàng Giá Trị Cao',
matchKeys: ['EMAIL', 'PHONE', 'FN', 'LN'],
syncMode: 'mirror'
});

Kéo Campaign Insights

// Lấy số liệu hiệu suất campaign
const insights = await tajo.connectors.query('meta-ads', {
resource: 'campaigns',
fields: ['campaign_name', 'impressions', 'clicks', 'spend',
'actions', 'cost_per_action_type'],
dateRange: { since: '2024-01-01', until: '2024-01-31' },
level: 'campaign'
});

Giới Hạn Tốc Độ

Tài NguyênGiới HạnChi Tiết
Marketing APITheo cấp bậcDựa trên app access level và chi tiêu
Custom Audience uploads700 yêu cầu/giờMỗi ad account
Conversions API2.000 events/giâyMỗi pixel
Insights API200 lần gọi/giờMỗi ad account
Lead retrieval200 lần gọi/giờMỗi page
Batch requests50 yêu cầu/batchMỗi batch call

Yêu Cầu Xác Minh Business

Truy cập đầy đủ Marketing API yêu cầu xác minh business trong Meta Business Manager. Ứng dụng chưa xác minh bị giới hạn ở development mode với giới hạn tốc độ hạn chế.

Khắc Phục Sự Cố

Sự CốNguyên NhânGiải Pháp
OAuthExceptionToken hết hạn hoặc không hợp lệTạo lại System User access token
Tỷ lệ match Custom Audience thấpChất lượng dữ liệu kémHash tất cả PII với SHA-256, bao gồm nhiều match keys
Conversions không được attributionThiếu tham số fbc/fbpTruyền Facebook Click ID và Browser ID từ cookies
RATE_LIMIT_REACHEDQuá nhiều API callsTriển khai exponential backoff, kiểm tra API access tier
Lead forms không đồng bộThiếu quyền leads_retrievalThêm quyền vào System User
Events ở test modetest_event_code vẫn được đặtXóa test event code cho production

Thực Hành Tốt Nhất

  1. Dùng System User tokens - System Users cung cấp tokens ổn định, không hết hạn cho server integrations
  2. Hash tất cả PII - SHA-256 hash tất cả thông tin nhận dạng cá nhân trước khi gửi sang Meta
  3. Gửi cả CAPI và Pixel - Dùng cả Conversions API và Meta Pixel để theo dõi dư thừa với deduplication
  4. Bao gồm event IDs - Đặt event_id trên cả CAPI và Pixel events để cho phép deduplication
  5. Truyền fbcfbp - Bao gồm Facebook Click ID và Browser ID để attribution conversion tối đa
  6. Xác minh business - Hoàn thành Business Verification để truy cập API đầy đủ và giới hạn tốc độ cao hơn
  7. Dùng test_event_code - Kiểm tra Conversions API events trong Events Manager trước khi đưa vào production

Bảo Mật

  • System User tokens - Tokens xác thực không cá nhân, được phạm vi theo business
  • SHA-256 hashing - Tất cả PII được hash trước khi truyền sang Meta servers
  • App Secret Proof - Lớp bảo mật xác thực bổ sung tùy chọn
  • Business scoping - Quyền được phạm vi cho ad accounts và pages cụ thể
  • Meta compliance - Tuân thủ Meta Platform Terms và advertising policies
  • Data Processing Terms - Meta’s Data Processing Terms áp dụng cho dữ liệu EU

Tài Nguyên Liên Quan

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

auto-detect
Trợ lý AI

Xin chào! Hãy hỏi tôi về tài liệu.