Last active
April 1, 2025 23:22
-
-
Save smhmic/11c39c5243d6f2b78087 to your computer and use it in GitHub Desktop.
console commands for GTM admin
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
gtm = { | |
'updateAllUserPermissions' : function( val ){ | |
val = val || 2; | |
// Update user permissions far all Containers in an Account | |
//https://tagmanager.google.com/#/admin/accounts/00000000/users/create | |
jQuery( '[data-ng-model="containerPermission.permission"]' ).val( val ).change() | |
}, | |
// Make Container export preview copyable. | |
// https://tagmanager.google.com/#/admin/accounts/0000/containers/00000/export | |
'copyContainerExport' : function(){ | |
var json,_json,lines,div,iframe,iw,versionSelect = jQuery('[data-ng-model="ctrl.selectedVersion"]'); | |
if( null === versionSelect.val() ){ | |
versionSelect.val( '0' ).change(); | |
return window.setTimeout(function(){ | |
jQuery('[data-ng-click="stepperCtrl.nextStep()"]').click(); | |
pfx.copyContainerExport(); | |
},9); | |
} | |
lines = jQuery('.CodeMirror-code pre'); | |
if( ! lines.length ) | |
return setTimeout( copyContainerExport, 9 ); | |
json = lines.text().trim(); | |
try{ | |
_json = JSON.parse( json ); | |
console.log(_json); | |
json = JSON.stringify( _json ); | |
} catch(ex){ console.error('Failed to parse JSON', ex); } | |
iframe = jQuery('<iframe style="position:fixed;top:0;bottom:0;right:0;height:100%;width:30%;z-index:999999;background:white;font-size:8px">'); | |
jQuery('body').append(iframe); | |
iw = iframe[0].contentWindow; | |
div = document.createElement('div'); | |
div.setAttribute('style','font-size:0.8em;font-family:monospace'); | |
div.appendChild(document.createTextNode(json)); | |
iw.document.body.appendChild( div ); | |
//iframe[0].src = 'javascript:window["contents"]'; | |
window.open('https://jqplay.org','_blank'); | |
}, | |
} |
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
gtm = { | |
// This one if for the front-end when debugging a Container ... to | |
// disable verbose logging in Debug Mode | |
'disableVerboseDebugLogging' : function(){ | |
document.querySelector( 'iframe[src*="about"]' ).contentWindow.angular.element( document.querySelector( 'iframe[src*="about"]' ).contentWindow.document.querySelector( '[ng-app]' ) ).injector().get( "$log" ).debug = function(){}; | |
}, | |
// | |
'dataLayerJson' : function(){ | |
JSON.stringify(dataLayer,true,"\t") | |
}, | |
// | |
'dataLayerJsonDownload' : function(){ | |
return pfx.util.download( dataLayer, 'dataLayer.json' ); | |
}, | |
// Prints datalayer frames in the console as theyre pushed | |
'watchDataLayer' : function(){ | |
Object.observe(dataLayer, function(c) { | |
for(i=0;i<c.length;i++) | |
{ | |
if(c[i].type=="add") | |
{ | |
console.log("%cNew dataLayer Push\n", "color: blue; font-size:15px;"); | |
console.log(JSON.stringify(c[i].object[c[i].name], null, '\t')); | |
} | |
} | |
}); | |
}, | |
// | |
'eec' : function(){ | |
//TODO | |
console.table(google_tag_manager[(Object.keys(google_tag_manager)[1])].dataLayer.get('ecommerce.impressions')); | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment