最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Tracking pixel with Angular.js - Stack Overflow

programmeradmin3浏览0评论

We are using facebook tracking pixel, to track the performance of our facebook ads. To do so, for every user that es to our service for the first time we need to fire tracking pixel in DOM. We do it by setting $scope.newReg to true in controller and with following code in template.

<div ng-if="newReg == true">
<img height="1" width="1" alt="" style="display:none" src=";amp;cd[value]=0.00&amp;cd[currency]=EUR&amp;noscript=1" />
</div>

The question is what is really going on if $scope.newReg is set to false. I guess that tracking pixel should'n be fired, but according to documentation it seems like it can be fired. "If condition is falsy then the element is removed from the DOM tree." Which means that tracking pixel could for a very short moment appear in the DOM and then being removed. And that would fire tracking counter even if condition fails.

We are using facebook tracking pixel, to track the performance of our facebook ads. To do so, for every user that es to our service for the first time we need to fire tracking pixel in DOM. We do it by setting $scope.newReg to true in controller and with following code in template.

<div ng-if="newReg == true">
<img height="1" width="1" alt="" style="display:none" src="https://www.facebook./tr?ev=xxxxxx&amp;cd[value]=0.00&amp;cd[currency]=EUR&amp;noscript=1" />
</div>

The question is what is really going on if $scope.newReg is set to false. I guess that tracking pixel should'n be fired, but according to documentation it seems like it can be fired. "If condition is falsy then the element is removed from the DOM tree." Which means that tracking pixel could for a very short moment appear in the DOM and then being removed. And that would fire tracking counter even if condition fails.

Share Improve this question asked Oct 7, 2014 at 16:48 Ladislav MLadislav M 2,1874 gold badges37 silver badges52 bronze badges 4
  • I think it depends on where your tracking pixel HTML is. – Raju Mandapati Commented Oct 7, 2014 at 16:54
  • If the above markup is inside the default html page that has ng-app, then this will be loaded into DOM before Angular bootstraps and evaluates ng-if directive. So YES, this would appear for a very short moment atleast if the style attribute doesn't say display:none. – Raju Mandapati Commented Oct 7, 2014 at 16:59
  • According to Facebook sample code, it has style attribute that says display:none. Anyway it's not about whether the pixel is actually shown, but about if it's being fired. – Ladislav M Commented Oct 8, 2014 at 19:17
  • The markup is inside partial file, so it is under specific controller. As we are using Ionic framework, we have ui-router for joining controllers and views. – Ladislav M Commented Oct 8, 2014 at 19:22
Add a ment  | 

2 Answers 2

Reset to default 3

Nobody else dealing with this issue?

This answer seems to be working for me: Facebook Custom Audience pixel on SinglePageApplication SPA

But I believe that there are more ways how to handle it.

I'd suggest you to not depend on ng-if documentation, that may change next version due to performance needs or just some bugs.

I suggest you to create your own tracking pixel directive that injects the html if conditions are good.

发布评论

评论列表(0)

  1. 暂无评论