Google Analytics Javascript code throwing Permission Denied error


I have a javascript code to use google analytics in an ASP.Net application. Following are the first two lines of it

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));

If I embed this in an aspx file it works fine but if I put it in a function and call that function on a client side button click, it gives me a javascript error of "Permission Denied". Can someone help me resolve this?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amandeep Singh BhullarCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimmysaundersAuthor Commented:
Thanks AmanBhullar but that discussion is entirely about something else.
The tracking should be placed at the end of your page, just before the closing body tag (</body>) See here:

I am not sure why you would want to add it to a button click. This link shows how you would add tracking to an Anchor tag :
jimmysaundersAuthor Commented:
Was looking for a wrong solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.