如何使用初始化后填充的数据初始化Facebook Pixel? [英] How to initialize Facebook Pixel with data that will be populated after the initialization?

查看:232
本文介绍了如何使用初始化后填充的数据初始化Facebook Pixel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单页的广告系列网站,应该收集 PageView LEAD Facebook定位的事件数据高级匹配。

I have a one-pager campaign site which should collect PageView and LEAD event data for Facebook targeting with "advanced matching".

对于 PageView ,我需要在页面加载时初始化Pixel。对于高级匹配,我需要为初始化脚本提供用户数据 - 但是,在用户提交数据后,我只有用户数据可用,即 LEAD 事件应该是已发送。

For PageView, I need to initialize the Pixel on page load. For advanced matching, I need to provide user data for initialization script — however, I only have user data available after user has submitted the data, which is when the LEAD event should be sent.

是否可以为初始化脚本提供指向发送 LEAD 活动?帮助页面提示,但所有示例都有例如电子邮件参数以纯文本或sha256哈希的形式提供;不是JS变量,也不是文本指针。

Is it possible to provide the initialization script with a "pointer" to a javascript variable that is used when sending the LEAD event? Help page hints at this, but all the examples have e.g. email parameter provided as plain text or sha256 hash; not as JS variable nor as a textual pointer to one.

来自与Pixel进行高级匹配帮助页面


要启用此功能,请修改默认的FB像素代码,将数据
传递到像素初始化调用中。

To enable this feature, modify the default FB pixel code to pass data into the pixel init call.

fbq('init', '<FB_PIXEL_ID>', { 
    em: '{{_email_}}', 
    // Data will be hashed automatically via a dedicated function in FB pixel
    ph: '{{_phone_number_}}',
    fn: '{{_first_name_}}'
    ....
})

在上面的示例中,您需要将电子邮件,phone_number,
first_name替换为您网站上变量的名称
捕获这些数据。

In the example above, you will need to replace email, phone_number, first_name with the names of the variables on your website that capture this data.

假设我有 user_email 变量范围为 fbq-init

var user_email = '';

稍后,在提交表单后,此变量将填充为

Later, after the form is submitted, this variable will be populated like

user_email = "john@example.com";

我应该如何在 fbq 中引用变量? ? (1)喜欢这个?

How should I reference the variable in fbq? (1) Like this?

fbq('init', 123456, { em: '{{_user_email_}}' });

(2)或者像这样?

fbq('init', 123456, { em: 'user_email' });

(3)或者我应该只提供变量:

fbq('init', 123456, { em: user_email }); // nb: user_email === false when this is run

(4)或者我应该初始化没有任何匹配数据的像素,以后再丰富它? (如何?)

(4) Or should I initialize the pixel without any matching data and later enrich it? (How?)

一位声誉良好的广告代理商向我发送了提交变量名称的说明,如我的示例2所示,但帮助页面提示为1但未实际提供任何现实世界的例子。

A reputable ad agency sent me with instructions to submit the name of the variable as in my example 2, but the help page hints at 1 without actually providing any real world examples.

我尝试了所有选项1-3,似乎变量不会重新获得初始化后,在后续的 fbq('track',...); 调用中进行评估。如果 user_email 以空白开头,则所有事件都不会包含散列用户数据。

I tried all the options 1–3, and it seems variables won't get re-evaluated in subsequent fbq('track', …); calls after the initialization. If user_email is blank to start with, none of the events will include hashed user data.

此外即使我从有效的电子邮件开始 user_email =john@example.com; (也尝试过真正的域而不是example.com)只有方法3可以工作 - 但是,正如预期的那样,这不是动态的,即。如果 user_email 更改哈希值不会。

Moreover even if I start with a valid email user_email = "john@example.com"; (also tried real domains instead of example.com) only method 3 will work — but, as expected, this is not dynamic, ie. if user_email changes the hashes won't.

就好像没有字符串变量替换开始使用。

It is as if there is no string-variable replacement to begin with.

更合适的问题是:如何在像素初始化后提交高级匹配的用户数据?而不是尝试使初始化延迟/动态。

Would the more proper question be: how do I submit user data for advanced matching after the pixel initialization? Instead of trying to make the initialization lazy/dynamic.

推荐答案

作为解决方法它是可以通过javascript加载像素(图片)来生成带有电子邮件用户数据的 Lead 事件:

As a workaround it is possible to generate a Lead event with email user data by loading the pixel (image) via javascript:

// here the user email is unknown, so PageView is generated without email
fbq('init', 123456, {});
fbq('track', 'PageView');

// Later the form is submitted via ajax, so the user email is known
$.ajax(…).done(function(data) {
    // I decided to sha256 hash the email address in the backend and return it for the javascript handler
    var pixel = document.createElement('img');
    pixel.src = 'https://www.facebook.com/tr/?id=123456&ev=Lead&ud[em]=' + data;
    document.body.appendChild(pixel);
    // confirmed by the Pixel helper Chrome extension, this does generate a valid tracking event
    // (ironically, we're loading the noscript version via javascript)
});

当然,纯粹的 fbq 版本会更可取。此外,我还没有意识到可能的缺点,如果有的话。

Of course, a pure fbq version would be more desirable. Also, I'm yet unaware of possible drawbacks, should there be any.

这篇关于如何使用初始化后填充的数据初始化Facebook Pixel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆