Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking a Google Sheets in Google Analytics

I am trying to collect hits/events from a Google Sheets into Google Analytics. These are the hits I need to collect:

  • How many people are active in that spreadsheet (this is OK)
  • Register when someone edits a column
  • Register users information (ID, email)
  • Register how long time user spent on spreadsheet

I have to use Measurement Protocol to actually send these data over to Google Analytics.

Is it possible to send these data without having own server, I mean directly from the script editor?

And how can I set up the Google Analytics - do I need to create some custom goals to get the information I need?

I found this script on GitHub:

function sendGAMP(tid, url){                                              
 var data = {'v': '1',
             'tid': tid, // TrackingID Google Analytics
             'cid': Utilities.getUuid(), // ClientID / UserID --> Session.getTemporaryActiveUserKey()
             'z': Math.floor(Math.random()*10E7),
             't':'pageview',
             'dl': url };                                                 var payload = Object.keys(data).map(function(key) {
                                    return encodeURIComponent(key) + '=' + encodeURIComponent(data[key]);
                                }).join('&');                             
  var options = {'method' : 'POST',
                 'payload' : payload };UrlFetchApp.fetch('http://www.google-analytics.com/collect', options); 

}

I don't need anyone to create me a code or something, I just need a little guidance how I can make this work. I tried to search on internet but I just found a tutorial on how to import Google Analytics to Sheets and not the other way.

like image 203
Asim Avatar asked Mar 22 '26 02:03

Asim


1 Answers

Yes, you can do that. You need to use Google Analytics Beacon. If you can embed a simple image (pixel tracker), then you can beacon data to Google Analytics. GA Beacon

If you intend to use this in production for your application, you should deploy your own instance of this service, which will allow you to scale the service up and down to meet your capacity needs, introspect the logs, customize the code, and so on.

Please follow the below link and make it work.

https://mashe.hawksey.info/2014/02/tracking-google-sheet-views-with-google-analytics/

like image 132
Tushar Avatar answered Mar 23 '26 21:03

Tushar