-
-
Save IronistM/fd4a3bd1870f3633223b2708cc54b89e to your computer and use it in GitHub Desktop.
Notifies you about pending changes in your GTM workspaces by email
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 myFunction() { | |
try { | |
var message = '' | |
var response = TagManager.Accounts.list() | |
response.account.map(function(account) { | |
Logger.log('fetching changes for %s', account.name) | |
var containers = TagManager.Accounts.Containers.list(account.path) | |
Utilities.sleep(5000) | |
if (!containers.container) { | |
Logger.log('no containers for %s', account.name) | |
return | |
} | |
containers.container.map(function(container) { | |
var workspaces =TagManager.Accounts.Containers.Workspaces.list(container.path) | |
Utilities.sleep(5000) | |
if (!workspaces.workspace) { | |
Logger.log('no workspaces for %s > %s', account.name, countainer.name) | |
return | |
} | |
workspaces.workspace.map(function(workspace) { | |
var status = TagManager.Accounts.Containers.Workspaces.getStatus(workspace.path) | |
Utilities.sleep(5000) | |
if (!status.workspaceChange) return | |
var changesList = status.workspaceChange.reduce(function(list, change) { | |
list[change.changeStatus] = list[change.changeStatus] || 0 | |
list[change.changeStatus]++ | |
return list | |
}, {}) | |
if (Object.keys(changesList).length) { | |
message += [account.name, 'has changes in', container.name, '>', workspace.name, ': '].join(' ') | |
Object.keys(changesList).map(function (key) { | |
message += key + ':' + changesList[key] + '; ' | |
}) | |
} | |
message += '\n' | |
}) | |
}) | |
}) | |
Logger.log(message) | |
MailApp.sendEmail('[email protected]', 'non published changes in GTM', message) | |
} catch (e) { | |
Logger.log(e) | |
MailApp.sendEmail('[email protected]', 'non published changes in GTM', 'script failed with ' + e.message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment