var sn_communities = sn_communities || {};

sn_communities.Google_GTM = (function(GlideAjax,g_form,GlideDialogWindow,GlideRecord){
    "use strict";

    var tagString = "<!-- Google Tag Manager -->";
    tagString += "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':";
    tagString += "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],";
    tagString += "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=";
    tagString += "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);";
    tagString += "})(window,document,'script','dataLayer','GTM-KSTVBHL');</script>";
    tagString += "<!-- End Google Tag Manager →";
    tagString += "<!-- Google Tag Manager (noscript) -->";
    tagString += "<noscript><iframe src='https://www.googletagmanager.com/ns.html?id=GTM-KSTVBHL'";
    tagString += "height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript>";
    tagString += "<!-- End Google Tag Manager (noscript) -->";

    var elemDiv = document.createElement('noscript');
    elemDiv.innerHTML = tagString;
    document.getElementsByTagName("body")[0].appendChild(elemDiv));

/* set your private variables and functions here. For example: 
	var privateVar = 0; 
	function private_function() {
		return ++privateVar;
	}
*/

/* Share variables between multiple UI scripts by adding them to your scope object. For example: 
	sn_communities.sharedVar = 0; 

 Then access them in your scripts the same way. For example: 
	function get_shared() {
		return sn_communities.sharedVar;
	}
*/

return {

    /* set your public API here. For example:
    		incrementAndReturnPrivateVar: function() {
    			return private_function();
    		},
    */
    type: "Google_GTM"
};
}.bind(sn_communities))(ScopedGlideAjaxGenerator("sn_communities"),ScopedGFormGenerator("sn_communities"),ScopedGlideDialogWindowGenerator("sn_communities"),null);