Skip to content

Instantly share code, notes, and snippets.

View chipoglesby's full-sized avatar
🏠
Working from home

Chip Oglesby chipoglesby

🏠
Working from home
View GitHub Profile
@chipoglesby
chipoglesby / cost.js
Last active August 29, 2015 14:20
Cost Checker - This MCC script will log the Client's Name and Cost
var dateRange = "THIS_MONTH";
function main() {
MccApp.accounts().withCondition("Cost > 1.00").forDateRange(dateRange).withLimit(50).executeInParallel('runOnEachAccount');
}
function runOnEachAccount() {
var stats = AdWordsApp.currentAccount().getStatsFor(dateRange);
var impressions = stats.getImpressions();
var clicks = stats.getClicks();
var cost = stats.getCost();
@chipoglesby
chipoglesby / Youtube.js
Last active August 29, 2015 14:20
Youtube Metrics via the Adwords API
var SPREADSHEET_URL = "YOUR URL HERE";
 
function main() {
  //These names are important. change them with caution
  var tabs = ['ABC123', 'ABC123 LM'];
  for(var i in tabs) {
    var results = runQuery(tabs[i]);
    writeToSpreadsheet(tabs[i],results);
  }
}
@chipoglesby
chipoglesby / format.js
Last active September 21, 2017 10:36
Format Your Google Spreadsheets & Youtube Reporting
function onOpen() {// Inserts a custom menu in the spreadsheet, lets you do neat stuff.
var ss = SpreadsheetApp.getActiveSpreadsheet(),
options = [
{name:"Format The Current Sheet", functionName:"formatSheet"}
];
ss.addMenu("Auto Formatter", options);
}
function formatSheet() {//Formats a single spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
@chipoglesby
chipoglesby / google_sheets.txt
Last active September 13, 2022 07:25
Common Google Spreadsheet Formulas
1. Identifying Cells by Type in Google Spreadsheets
=if(index(split(D1, "::"),1) = "mobileapp", "Mobile", "Website")
-------
2. Get the root domain url of a cell in Google Spreadsheets
For sites with one TLD or one TLD and one subdomain: ie: xx.com or xx.xx.com
=iferror(join(".", index(split(A2, "."),2),index(left(split(A2, "."),3),3)), join(".", index(split(A2, "."),1),index(left(split(A2, "."),3),2)))
@chipoglesby
chipoglesby / index.js
Last active October 23, 2023 01:23
Automatically move the sheets in a spreadsheet into alphabetical order.
function sortSheets(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetNameArray = [];
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
sheetNameArray.push(sheets[i].getName());
}
sheetNameArray.sort();
for( var j = 0; j < sheets.length; j++ ) {
ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j]));
@chipoglesby
chipoglesby / mcc_cost.js
Created May 8, 2015 14:59
Google Adwords MCC script will run on the MCC level and log cost for given date range
var dateRange = "THIS_MONTH";
function main() {
MccApp.accounts().withCondition("Cost > 1.00").forDateRange(dateRange).withLimit(50).executeInParallel('runOnEachAccount');
}
function runOnEachAccount() {
var stats = AdWordsApp.currentAccount().getStatsFor(dateRange);
var impressions = stats.getImpressions();
var clicks = stats.getClicks();
var cost = stats.getCost();
@chipoglesby
chipoglesby / skip.gs
Last active May 24, 2018 13:36
Remove Extra Columns in Google Spreadsheet
function removeExtraColumns() {// Formats all spreadsheets
var ss = SpreadsheetApp.getActive();
for(var n in ss.getSheets()){// loop over all tabs in the spreadsheet
var sheet = ss.getSheets()[n];// look at every sheet in spreadsheet
var name = sheet.getName();//get name
var maxColumns = sheet.getMaxColumns();
var lastColumn = sheet.getLastColumn();
var subtract = maxColumns - lastColumn;
var lastNew = lastColumn + 1;
if(name != "*test"&& subtract > 0){
@chipoglesby
chipoglesby / conditional-formatting.js
Last active May 18, 2022 23:34
Conditional Formatting in Google App Script based on cell value
//If the current cell is more than the previous cell, set it as lime green
function onEdit(e) {
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var name = sheet.getName();
var range = sheet.getRange("A:J");
var values = range.getValues();
var cell = sheet.getActiveCell();
var value = cell.getValue();
@chipoglesby
chipoglesby / Translate.js
Last active August 29, 2015 14:21
Translating Google Spreadsheet cells using Google Translate
function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var name = sheet.getName();
var cell = sheet.getActiveCell();
var value = cell.getValue();
if (typeof value == 'string') {
var spanish = LanguageApp.translate(value, 'en', 'es');
cell.setValue(spanish);
}
}
@chipoglesby
chipoglesby / gmail.gs
Last active October 25, 2018 06:44
Google App Script to Scan Gmail for payment emails from Adwords
var SPREADSHEET_URL = "url";
function main() {
var name = ("Google Adwords/Recieved Payment");
var label = GmailApp.getUserLabelByName(name);
var unreadCount = label.getUnreadCount();
var threads = label.getThreads(0,10);
for (var n = 0; n < threads.length; n++) {
var inbox = threads[n].isInInbox();
var message = threads[n].getMessages();
var lastDate = new Date(threads[n].getLastMessageDate());