Created
August 1, 2018 10:34
-
-
Save postman31/93b911567946a5ae3a1f4b82ed5910cf to your computer and use it in GitHub Desktop.
Notifies you about pending changes in your GTM workspaces by email
This file contains 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 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