skip to main | skip to sidebar

Friday, September 26, 2008

Google Analytics and the ASP.NET wizard control

I've search Google long and hard... and to my frustration no one else was able to figure this out yet, so here is my working solution for getting Google Analytics to be able to track the steps within an ASP.NET Wizard control.

First you will need to define the StartNavigationTemplate, StepNavigationTemplate, and FinishNavigationTemplate. I just stuck with something simple a Next button for the Start, Previous and Next for step, and Previous and Finish for finish.

You will need to define two functions for each. OnClick you will need to advance the Wizard forward so really only need three functions you can reuse StepNextClick, StepPreviousClick, and StepFinishClick.

The tricky part is you need to add a OnPreRender function to all the buttons. I used just two functions here on the forward buttons I used "FixPostBackNext" and "FixPostBackPrevious". Both are pretty simple functions and here is some sudo code below:

FixPostBackNext(object sender, EventArgs e)
{
Button nextButton = (Button)sender;
nextButton.PostBackUrl = Page.Url + QuerystringVariable + (CurrentWizardStep + 1)
}

FixPostPagePrevious(object sender, EventArgs e)
{
Button prevButton = (Button)sender;

if (CurrentWizardStep == 1)
{
prevButton.PostBackUrl = Page.Url;
}
else
{
prevButton.PostBackUrl = Page.Url + QuerystringVariable + (CurrentWizardStep - 1)
}

}

Bam! You now have querystrings added to your ASP Wizard control for your Google Analytics without changing the functionality of your Wizard.

 


You are viewing a mobilized version of this site...
View original page here

How do you rate mobile version of this page?

Mobilized by Mowser Mowser