Skip to content

Instantly share code, notes, and snippets.

@xtornasol512
Last active October 30, 2017 17:39
Show Gist options
  • Save xtornasol512/897a584963f1402be1facb45afd16fac to your computer and use it in GitHub Desktop.
Save xtornasol512/897a584963f1402be1facb45afd16fac to your computer and use it in GitHub Desktop.
Scrapping data users user sessions time on Google analytics
// _GAZeb Id de Cliente
// _GAvi Parent Element (days)
// _GAOyb Fecha (date)
// _GAMI Hora (hour)
// Script to retrieve data from
// Create Data Sessions for clients
console.clear();
var sessions_client = []
// Get client ID
var client_id = $("._GAZeb")[0].innerHTML;
$("._GAvi").each(function(index){
// Initialize
var date = $('._GAOyb', this)[0].innerHTML;
// get all hours
$('._GAMI', this).each(function(){
item = []
item[0] = client_id;
var hour = this.innerHTML;
item[1] = date;
item[2] = hour;
sessions_client.push(item);
});
// break for debug
// return false;
})
// show content
// console.log('Total sessiones \n' + sessions_client)
// save content on a csv file
var csvContent = "data:text/csv;charset=utf-8,";
sessions_client.forEach(function(infoArray, index){
var dataString = infoArray.join("\t");
csvContent += index < sessions_client.length ? dataString+ "\n" : dataString;
});
// download the content
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment