0

I want to track internet speed(2G, 3G, 4G, wifi, etc) of the user using Google tag manager. Let me know the step for this

2 Answers2

1

It is not possible to do that with Google Tag Manager by default.

It is a definitely bad practice for your website visitors, but if you want to know their speed in MB/s (it is not very precise), you can do that following:

1) Create API endpoint on your website which will respond exact 1MB of any data.

2) Write JS code, which will measure how much time they spent on downloading 1MB data

var start_time = new Date().getTime();

jQuery.get('your-url'+ '?timestamp=' + new Date.getTime().toString(), 
    function(data, status, xhr) {
        var request_time = new Date().getTime() - start_time;
        var mbs= 1/(request_time/1000.0); //this variable will have speed in MBS
        dataLayer.push({'speed': mbs});
    }
);

3) Read this dataLayer in GTM

Again, it is a bad practice and it is not very precise

Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36
0

Victors answer, as unprecise as the results may be, is probably the easiest way (and for most use cases having a few buckets for the users should be okay). It will also work in any halfway modern browser. An implementation that does not rely on jQuery can be found in this very old answer (you'd need to adapt this to push the value to the datalayer).

For completeness sake:

  • There are also dedicated services to measure connection speed (I'm not affiliated, I just googled it).
  • If you are feeling adventurous you might want to explore the Network Information API, which is currently mostly useless due to almost non-existent browser support, but might be implemented at some point in the future (the downlinkMax property should give you the maximal possible speed for downloads)
Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62