locked
how to add google analytics goal to a asp:button click RRS feed

  • Question

  • User1555839508 posted

    Hello Experts,

    i am currently using Google Analytics to collects stats about my site ( my site is created in ASP.NET 2.0 and C#).

    i have asp:imagebutton called "Confirm Order". i want to track the clicking of this button.
    the code for this button is as follows:

    void ibConfirm_Click( object sender, ImageClickEventArgs e )
        {
            try
            {
                if ( Cart.Order.Items.Length == 0 )
                {
                    Mysite.ClearBasket( );
                    Response.Redirect( string.Concat(
                        ConfigurationManager.AppSettings[ "HTTPDirectory" ],
                        "cart.aspx?sto=true" ) );
                }
           
           
            Cart.Order.Purchase( );
                                   
            sendConfirmationEmail( Cart.Order );
         
            Mysite.ClearBasket();

            Server.Transfer("thanks.aspx", false);
           }
            catch (Exception ex)
            {
            this.HandlePageError(ex);
            }
           
        }


    my question how can i add the GA tracking script to this button click in the code behind.

    my GA tracking Script is like below:

    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document
    .write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try{
    var pageTracker = _gat._getTracker("UA-xxxxxx-x");
    pageTracker
    ._trackPageview();
    pageTracker._trackEvent('confirmOrder', 'Submit');
    } catch(err) {}</script>

    Thanks and i really appreciate any help.

    I want to know how i can add this script to the onclick code above to so i can track the button clicks.

    Thanks


    Friday, February 19, 2010 9:27 AM

Answers

  • User-294030300 posted

    Hey,

    The image button should have an OnClientClick property, which you can define the JS code that will run before the control posts back.  Reference that method from there.

    HTH. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2010 10:47 AM

All replies

  • User-294030300 posted

    Hey,

    The image button should have an OnClientClick property, which you can define the JS code that will run before the control posts back.  Reference that method from there.

    HTH. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2010 10:47 AM
  • User1555839508 posted

    Thanks for replying appreciate it, but since i am already using onclick method for the imageButton, now if i use OnClientClick, does this not result in double clicking,

    or does this throw an error....... sorry i am just in a learning stage.

    Thanks

    Friday, February 19, 2010 11:45 AM
  • User1555839508 posted

    thanks that did the trick

    Friday, February 19, 2010 7:08 PM