Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue migrating from GA to GTAG on ionic/cordova web app

Description

Since old GA SDK is getting obsolete, we are migrating to GTAG. While migrating, I found this line :

ga('set', 'checkProtocolTask', null);

which disables the protocol check so that GA script works in a webview (where cordova uses the file:// protocol apparently)

What I've tried

I looked through the internet (about 2-3 pages of "similar but not quite the same" problems)

Only solution I found is there : https://support.google.com/analytics/answer/7475953?hl=uk TLDR : add a script in Google Tag Manager, which will disable the protocol check for all trackers in google analytics and use that script in Google Analytics setup.

But : * we are not using Google Tag Manager as of now, so we'd have to set the thing up just for that. * it seems like a dirty hack to me... But it's not better than the old version I guess... * I don't think it's good to have this piece of code in Tag Manager, when everything else is in GIT repo. * It means we are disabling the protocol check, wherever it is called. Whereas the "hack" we had only disabled the protocol check when building the mobile app (desktop web was working without this line)

Is there no other solutions ? am I wrong ?

like image 652
Nanane Avatar asked Dec 11 '25 02:12

Nanane


1 Answers

So... I just realised that using global site tag just uses ga as we used to. So I actually ended up using the solution from the page I found : https://support.google.com/analytics/answer/7475953?hl=uk

Only I used that code snippet in my page instead of in a GTM variable. So whenever I load my page, I do

ga(function() {
    var trackers = $window.ga.getAll();
    trackers.forEach(function(tracker) {
    tracker.set('checkProtocolTask', null);
    });
});

I wrapped the snippet in a function() {...}, that way it is apparently run after ga is initialized.

like image 75
Nanane Avatar answered Dec 13 '25 15:12

Nanane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!