如何使用初始化后填充的数据初始化Facebook Pixel?

编程入门 行业动态 更新时间:2024-10-27 08:33:18
本文介绍了如何使用初始化后填充的数据初始化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";

我应该如何在 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; (也尝试过真正的域而不是example)只有方法3可以工作 - 但是,正如预期的那样,这不是动态的,即。如果 user_email 更改哈希值不会。

Moreover even if I start with a valid email user_email = "john@example"; (also tried real domains instead of example) 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 = 'www.facebook/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?

本文发布于:2023-11-22 23:44:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   如何使用   数据   Pixel   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!