Last active
April 29, 2020 06:28
-
-
Save narcan-zz/86e1523a4bd1b63bd1018710ce52d96e to your computer and use it in GitHub Desktop.
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
// export a configuration from a source GTM container and merge import it with a target GTM container | |
// from: https://developers.google.com/tag-manager/api/v1/ | |
// Get the published version of the source container | |
// GET https://www.googleapis.com/tagmanager/v1/accounts/{{accountId}}/containers/{{containerId}}/versions/published | |
source = tagmanager.accounts().containers().versions().get( | |
accountId='123456', | |
containerId='54321', | |
containerVersionId='2' | |
).execute() | |
// Create a version in the target container | |
// POST https://www.googleapis.com/tagmanager/v1/accounts/{{accountId}}/containers/{{containerId}}/versions | |
target = tagmanager.accounts().containers().versions().create( | |
accountId='123456', | |
containerId='54321', | |
body={ | |
'name': 'Container Version', | |
'notes': 'Sample Container Version', | |
'quickPreview': True | |
} | |
).execute() | |
// Construct a request body (in the form of a Container Version Resource) based on the difference between the source container and the target container | |
body = target + diff(source, target) | |
body.name = 'Updated Container Version' | |
body.notes = 'This Container Version was updated' | |
// Update this version in the target container | |
// PUT https://www.googleapis.com/tagmanager/v1/accounts/{{accountId}}/containers/{{containerId}}/versions/{{containerVersionId}} | |
tagmanager.accounts().containers().versions().update( | |
accountId='123456', | |
containerId='54321', | |
containerVersionId='2', | |
body=body | |
).execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment