将FB像素事件代码添加到按钮中-Squarespace [英] Add FB pixel event code into button - Squarespace

查看:321
本文介绍了将FB像素事件代码添加到按钮中-Squarespace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Squarespace的新手. 我的客户想为此跟踪网页浏览量,我已将基本像素代码注入所有网页的页眉中,并且效果很好,

I am new to squarespace. My client wants to track the page views for this, I have injected Base pixel code to header of all pages and it worked perfect,

但是现在她想跟踪,如果用户单击此页面上的任何购买按钮

But now she wants to track , if the user click on any buy button on this page

我不知道如何将Facebook像素代码注入到方形空间中的按钮上,任何想法或参考都将不胜感激. 谢谢

I have no idea how to inject facebook pixel code to a button in squarespace, any idea or reference would be highly appreciated . Thanks

推荐答案

听起来您想做的就是添加一个事件代码";要么:

It sounds like what you want to do is add an "Event Code" either:

  • A)到用户在单击按钮后看到的页面,或者
  • B)按钮本身.

如果您使用的是上一个选项(A),那么您要确保用户登陆的页面实际上指示您正在跟踪的事件,并且用户未到达该页面页面用于任何其他目的.这就是为什么我倾向于后一种选择(B).

If you're going with the prior option (A), then you'd want to make sure that the page upon which the user lands does in fact indicate the event you're tracking and that users do not arrive to that page for any other purpose. That is why I would lean towards the latter option (B).

您可以在此处此处,但摘要:

事件是由于以下原因在您的网站上发生的操作: Facebook广告(付费)或自然覆盖面(未付费).事件代码可让您 跟踪这些动作并在广告中加以利用.

Events are actions that happen on your website, either as a result of Facebook ads (paid) or organic reach (unpaid). The event code lets you track those actions and leverage them in advertising.

您可以发送两种类型的事件:

There are two types of events you can send:

  • 标准事件. 9个事件,我们无需进行任何其他操作即可跟踪和优化您的广告...
  • 自定义事件.对您的业务很重要的操作,但是如果没有其他操作,您将无法将它们用于跟踪和优化...
  • Standard events. 9 events we're able to track and optimize your ads for without any additional actions...
  • Custom events. Actions that are important to your business, but that you can’t use for tracking and optimization without additional action...

...

如果您认为这些按钮是添加到购物车"动作类型,则可以使用AddToCart事件.为此,您可以使用类似于以下内容的Javascript:

If you were to consider these buttons to be an "Add to Cart" type-of-action, then you'd use the AddToCart event. To do so, you could use Javascript similar to the following:

<script>
    window.Squarespace.onInitialize(Y, function() {
        var btns = document.getElementsByClassName("sqs-block-button-element");
        var i;
        for (i=btns.length-1; i>=0; i--) {
            btns[i].addEventListener("click", function() {
                fbq("track", "AddToCart");
            });
        }
    });
</script>

您可以使用每页代码注入或通过整个网站范围内的代码注入.我建议使用以前的版本,否则您网站上的所有按钮都将执行fbq事件代码,这可能是不可取的.

You could inject this code using per-page code injection or via site-wide code injection. I would recommend the prior, otherwise all buttons on your site will execute the fbq event code, which is probably undesirable.

无论您使用站点级注入还是每页注入,您都可能希望使用更具体的选择器来更好地定位按钮.例如,您可以使用querySelectorAll并按href属性定位.但是,如果您使用每页注入,则我提供的代码应该可以工作.它将应用于该页面上的每个按钮.

Regardless of whether you use site-wide or per-page injection, you may want to better target the buttons using a more specific selector. For example, you could use querySelectorAll and target by href attribute. However, if you use per-page injection, the code I supplied should work; it will apply it to every button on that page.

这篇关于将FB像素事件代码添加到按钮中-Squarespace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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