Is there a possibility to exclude fetching Google Analytics, Google Tag Manager and Facebook Pixel scripts via Service Worker in PWA?
From what I found out today - Facebook Pixel Helper and Google Tag Assistant return errors after reload if a website uses Service Workers. I'm not entierly sure if the data is not sent though (Chrome Dev Tools show that request to Facebook and Google is beeing sent with code 200).
It looks like both scripts fire on the first visit but won't fire on reload. I have no programming experience and have a vague notion of how Service Workers work but I need to make sure that I get all the data correctly because I'm an analyst. Can anyone point me to the right direction?
If you have problem with facebook pixel, you can try this way. You should exclude facebook request in your service worker.
self.addEventListener('fetch', function(event) {
if(event.request.url.search("www.facebook.com") != -1 || event.request.url.search("connect.facebook.net") != -1){
// hack FB Pixel
}else{
event.respondWith(
fetch(event.request).catch(function(error) {
console.log( '[PWA Builder] Network request Failed. Serving content from cache: ' + error );
//Check to see if you have it in the cache
//Return response
//If not in the cache, then return error page
return caches.open('pwabuilder-offline').then(function (cache) {
return cache.match(event.request).then(function (matching) {
var report = !matching || matching.status == 404?Promise.reject('no-match'): matching;
return report
});
});
})
);
}
});
In the same way you can hack Google Tag Assistant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With