Tracking a Google Sheets in Google Analytics

Viewed 1382

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.

1 Answers
Related