Created
July 11, 2025 17:38
-
-
Save jhpacker/0f4f3a44888a15e35d860a3b646cac8b to your computer and use it in GitHub Desktop.
Supermetrics Highlighter
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
// Supermetrics Highlighter - from Quantable.com | |
// Google App Script code that toggles a background color on any cells that have SM automation | |
const SM_COLOR = '#fffd03'; | |
const BG_PREFIX = 'BG_'; | |
function highlightSupermetricsOutputs() { | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const meta = ss.getSheetByName('SupermetricsQueries'); | |
if (!meta) return; | |
const data = meta.getRange(21, 4, meta.getLastRow() - 20, 2).getValues(); // D sheet, E range | |
const props = PropertiesService.getDocumentProperties(); | |
data.forEach(([sheetName, addr]) => { | |
if (!sheetName || !addr) return; | |
// Remove trailing single quote if present (Supermetrics bug with spaces in sheet names) | |
const cleanSheetName = sheetName.endsWith("'") ? sheetName.slice(0, -1) : sheetName; | |
const sh = ss.getSheetByName(cleanSheetName); | |
if (!sh) return; | |
const rng = sh.getRange(addr); | |
const key = BG_PREFIX + cleanSheetName + '!' + addr; | |
if (!props.getProperty(key)) { | |
props.setProperty(key, JSON.stringify(rng.getBackgrounds())); | |
} | |
rng.setBackground(SM_COLOR); | |
}); | |
} | |
function restoreSupermetricsBackgrounds() { | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const props = PropertiesService.getDocumentProperties(); | |
const all = props.getProperties(); | |
Object.keys(all).forEach(key => { | |
if (!key.startsWith(BG_PREFIX)) return; | |
const [sheetNameAddr] = key.slice(BG_PREFIX.length).split(';'); | |
const bang = sheetNameAddr.indexOf('!'); | |
const sheetName = sheetNameAddr.slice(0, bang); | |
const addr = sheetNameAddr.slice(bang + 1); | |
const sh = ss.getSheetByName(sheetName); | |
if (!sh) return; | |
const rng = sh.getRange(addr); | |
const bg = JSON.parse(all[key]); | |
rng.setBackgrounds(bg); | |
props.deleteProperty(key); | |
}); | |
} | |
function onOpen() { | |
SpreadsheetApp.getUi() | |
.createMenu('SM Highlighter') | |
.addItem('Highlight Automated Fields', 'highlightSupermetricsOutputs') | |
.addItem('Remove Highlighting', 'restoreSupermetricsBackgrounds') | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment