Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

xml, google script c#

I try to register the script below, and show on default.aspx

the codes look right but don't work to me. Please help.
protected void Page_Load(object sender, EventArgs e)
{
	string googleScript = string.Empty;
	if (domainName.Contains("aaa.com"))
	{
	 googleScript = "<script async src='https://www.googletagmanager.com/gtag/js?id=UA-923423499-4'></script>" +
               "<script> window.dataLayer = window.dataLayer || []; " +
               " function gtag(){ dataLayer.push(arguments); } " +
               " gtag('js', new Date()); " +
               " gtag('config', 'UA-923423499-4'); " +
               "</script>";
	}
	if (googleScript != "")
        {
                Page.ClientScript.RegisterStartupScript(this.GetType(), googleScript,"",true);
        }
}

//my goal is to add <script></script> on aspx webpage

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
have you tested it out? it worked for me.
as proposed