Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Notifies you about pending changes in your GTM workspaces by email
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 chanshesList = status.workspaceChange.reduce(function(list, change) {
list[change.changeStatus] = list[change.changeStatus] || 0
list[change.changeStatus]++
return list
}, {})
if (Object.keys(chanshesList).length) {
message += [account.name, 'has changes in', container.name, '>', workspace.name, ': '].join(' ')
Object.keys(chanshesList).map(function (key) {
message += key + ':' + chanshesList[key] + '; '
})
}
message += '\n'
})
})
})
Logger.log(message)
MailApp.sendEmail('me@example.com', 'non published changes in GTM', message)
} catch (e) {
Logger.log(e)
MailApp.sendEmail('me@example.com', '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