troubleshooting Question

Run Google Analytics tracking code from ASP.NET code behind file (.cs)

Avatar of webressurs
webressursFlag for Norway asked on
ASP.NETJavaScriptAnalytics
1 Comment1 Solution1439 ViewsLast Modified:
Hi!

Is it possible to run a Google Analytics tracking code from ASP.NET code behind (default.aspx.cs)?

Here is the Google tracking script:
<script>
$j = jQuery.noConflict();
$j(function () {
analytics.track('Paid User created');
});
</script>

This script above shall only run in some cases. That's why I need to run it from the code behind file:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
        {
            if (SecurePayment == true)
            {
                PayWithSecure();
            }
            else
            {
                PayWithoutSecure();
            }
        }
    }

    protected void PayWithSecure()
    {
        if (someting)
        {
            //RUN GOOGLE TACKING CODE
        }
        else
        {
            //....
        }
    }

    protected void PayWithoutSecure()
    {
        if (someting)
        {
            //RUN GOOGLE TACKING CODE
        }
        else
        {
            //....
        }
    }

}
ASKER CERTIFIED SOLUTION
Randy Poole

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros