Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cost Data Upload via Google Analytic's Management API with Google Sheets
function uploadData() {
var accountId = "xxxxxxxx";
var webPropertyId = "UA-xxxxxxxx-x";
var customDataSourceId = "xxxxxxxx";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var maxRows = ss.getLastRow();
var maxColumns = ss.getLastColumn();
var data = [];
for (var i = 1; i <= maxRows;i++) {
data.push(ss.getRange([i], 1,1, maxColumns).getValues());
}
var newData = data.join("\n");
var blobData = Utilities.newBlob(newData, "application/octet-stream", "GA import data");
try {
var upload = Analytics.Management.Uploads.uploadData(accountId, webPropertyId, customDataSourceId, blobData);
SpreadsheetApp.getUi().alert("Uploading: OK");
}
catch(err) {
SpreadsheetApp.getUi().alert("Cannot upload: Failed");
}
}
@kristijanPetr

This comment has been minimized.

Copy link

@kristijanPetr kristijanPetr commented Oct 26, 2016

Hi,
I've tried this solution and also using REST API , but when uploading the file it shows under Filename column: unknown filename.
Do you also had that problem ?
Thank you

unknownfilename

@jhpacker

This comment has been minimized.

Copy link

@jhpacker jhpacker commented Jun 21, 2017

This is a nice solution, though I have run into the same issue as @kristijanPetr, did either of you come across a fix for that?

@williamjulianvicary

This comment has been minimized.

Copy link

@williamjulianvicary williamjulianvicary commented Aug 13, 2017

I'm also looking for a resolution for "Unknown filename" @jhpacker or @krisijanPetr - did any of you uncover a fix?

@matjazzidaric

This comment has been minimized.

Copy link

@matjazzidaric matjazzidaric commented Jul 31, 2018

Hi, did any of you find a solution how to name files via this method? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment