I have enabled facebook pixel into my angular webApp. But it only works on if i hard refresh. After that the request gets triggered via service worker and not getting registered in the facebook pixel extension.
I have tried including the links into the dataGroups.
I have also tried the ngsw-bypass=true query param
我已经在我的棱角网络应用程序中启用了Facebook Pixel。但它只有在我努力刷新的情况下才能起作用。在此之后,请求通过服务工作者触发,而不是在Facebook像素扩展中注册。我已尝试将链接包含到数据组中。我还尝试了ngsw-略过=True查询参数
Everything works fine if i remove the service worker from my app.
如果我从我的应用程序中删除服务人员,一切正常。
ngsw-config.json
{
"index": "/index.html",
"dataGroups": [
{
"name": "api",
"urls": ["https://connect.facebook.net/en_US/fbevents.js","https://connect.facebook.net/signals/config/**"],
"cacheConfig": {
"maxSize": 0,
"maxAge": "0u",
"strategy": "freshness"
}
}
],
"assetGroups": [
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
load() {
if (!this.loadOk) {
(function (f: any, b, e, v, n, t, s) {
if (f.fbq) return; n = f.fbq = function () {
n.callMethod ?
n.callMethod.apply(n, arguments) : n.queue.push(arguments)
}; if (!f._fbq) f._fbq = n;
n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0;
t.src = v; s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s)
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js?ngsw-bypass=true');
// (window as any).fbq.disablePushState = true; //not recommended, but can be done
(window as any).fbq('init', '1117176809040790');
(window as any).fbq('track', 'PageView');
this.loadOk = true;
console.log('Facebook pixel init run!')
}
else {
(window as any).fbq('track', 'PageView');
console.log('Facebook PageView event fired!')
}
}
更多回答
Pretty sure you dont need to add anything to the ng-sw for facebook connect. Also the image shown was cache from disk, not from service worker. I would just remove the facebook api data group. And it should work just fine.
可以肯定的是,您不需要向ng-sw添加任何内容即可实现Facebook连接。此外,显示的图像是来自磁盘的缓存,而不是来自服务工作人员的缓存。我只会删除Facebook API数据组。而且它应该运行得很好。
Hi Henrik, added another image below. What i meant is that the request is triggered from the worker as shown in the new image and it doesn't get logged in pixel extention. Adding The data group part is one among the various fixes that I have tried adding. I just doesn't work with or without it. Like I already mentioned in the question that pixel works perfectly fine if I remove service worker from the app.
嗨,亨里克,在下面添加了另一张图片。我的意思是,请求是从Worker触发的,如新图像所示,它不会记录在像素扩展中。添加数据组部件是我尝试添加的各种修复之一。不管有没有它,我都不会工作。就像我已经在问题中提到的,如果我从应用程序中删除服务人员,Pixel工作得非常好。
优秀答案推荐
我是一名优秀的程序员,十分优秀!