Last active
January 26, 2018 16:24
-
-
Save jrosell/128fdedc6f3f350a7648e7e3013a2af0 to your computer and use it in GitHub Desktop.
Google Analytics Cost Data Import from Google Sheets automated using Google Apps Scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(err); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment