Skip to content

Instantly share code, notes, and snippets.

@chipoglesby
Last active November 29, 2020 19:27

Revisions

  1. chipoglesby revised this gist Sep 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion costdata.gs
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ function uploadData() {
    var maxRows = ss.getLastRow();
    var maxColumns = ss.getLastColumn();
    var data = [];
    for (var i = 1; i < maxRows;i++) {
    for (var i = 1; i <= maxRows;i++) {
    data.push(ss.getRange([i], 1,1, maxColumns).getValues());
    }
    var newData = data.join("\n");
  2. chipoglesby revised this gist Sep 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion costdata.gs
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,6 @@ function uploadData() {
    SpreadsheetApp.getUi().alert("Uploading: OK");
    }
    catch(err) {
    SpreadsheetApp.getUi().alert("Cannot uploading: Failed");
    SpreadsheetApp.getUi().alert("Cannot upload: Failed");
    }
    }
  3. chipoglesby created this gist Sep 10, 2015.
    21 changes: 21 additions & 0 deletions costdata.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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 uploading: Failed");
    }
    }