ASP.NET integration code

From ClickTale Wiki
Jump to: navigation, search
ClickTale Wiki
The instructions on this page are intended for self service and online accounts.
Enterprise customers should contact their account managers for integration support.
If possible, use the ASP.NET integration module instead. It provides better integration with our service.
The only reason to use this code is if you are unable to install a binary module on your site.


If your ASP.NET web site uses sessions (storing data in the Session[] object) or .NET's built-in Forms Authentication then ClickTale may not be able to record your pages correctly by default. This code will provide you with an ASP.NET "Web User Control" that will not only allow you to add ClickTale easily to your pages, but will also allow ClickTale to do correct caching of "session" dependant and "Forms Authentication" protected pages. This sample was developed and tested for ASP.NET 2.0 . It won't work with ASP.NET 1.x because the cookieless="AutoDetect" attribute is not supported prior to ASP.NET 2.0.

Contents

Instructions

Step 1

Modify your web.config file to allow cookieless session and authentication modes. Find your system.web/authentication/forms tag and add an attribute that looks like this: cookieless="AutoDetect" . Find your system.web/sessionState tag and add cookieless="AutoDetect" attribute too. If you don't have one of those tags then you might be not using session or Forms Authentication or you may be using the default values. Add the tags when needed. Here is an example of an XML snippet:

   <system.web>
      <authentication mode="Forms">
      <forms loginUrl="Login.aspx" protection="All" timeout="30"
             cookieless="AutoDetect"             
             defaultUrl="~/admin/UserPage.aspx">
            <credentials passwordFormat="Clear">
               <user name="Arik" password="Password"/>
            </credentials>
         </forms>
      </authentication>
      <compilation debug="true"/>
  <sessionState
     mode="InProc"
     cookieless="AutoDetect"
     regenerateExpiredSessionId="true"
     timeout="30" />
  </system.web>

Step 2

Save the following block to the root of your website as ClickTale.ascx file

<%@ Control Language="C#" ClassName="ClickTale" %>
 
<script runat="server">
   // Copyright 2007 ClickTale Ltd.
   private string FullUrl;
 
   protected void Page_Load(object sender, EventArgs e)
   {
      string FullPath = Page.Request.Url.GetLeftPart(UriPartial.Path);
      int ScriptNamePos = FullPath.LastIndexOf("/");
      string VirtualPath = FullPath.Substring(0, ScriptNamePos + 1);
      string ScriptName = FullPath.Substring(ScriptNamePos + 1) + Page.Request.Url.Query;
 
      StringBuilder s = new StringBuilder(VirtualPath);
      s.Append("(X(1)");
      if (Page.Session.SessionID != null)
         s.AppendFormat("S({0})", Page.Session.SessionID);
      if (Page.Request.Cookies[FormsAuthentication.FormsCookieName] != null
         && Page.Request.Cookies[FormsAuthentication.FormsCookieName].Value != null
         && Page.Request.Cookies[FormsAuthentication.FormsCookieName].Value != "")
         s.AppendFormat("F({0})", Page.Request.Cookies[FormsAuthentication.FormsCookieName].Value);
      s.Append(")/");
      s.Append(ScriptName);
 
      FullUrl = s.ToString();
   }
</script>
 
<!-- ClickTale Bottom part -->
<div id="ClickTale" style="display: none;"></div>
<script src="http://s.clicktale.net/WRa.js" type="text/javascript"></script>
<script type="text/javascript">
ClickTaleFetchFrom='<%= FullUrl%>';
if(typeof ClickTale=='function') ClickTale([!YOUR PROJECT ID!],[!YOUR RATIO!]); // set your values here
</script>
<!-- ClickTale Bottom part end -->

You will need to insert your IDs and parameters in the bottom of the file. You should compare the code in the sample to the code you regularly use. Your code may be newer or better so you might want to edit the file to match. Make sure you keep this line:

ClickTaleFetchFrom='<%= FullUrl%>';

It is the one that does the magic.

Step 3

Add the "ClickTale Web User Control" to your pages. You can do that individually for each file or you can add the control to your master template (recommended). To do that, add the line

<%@ Register Src="~/ClickTale.ascx" TagName="ClickTale" TagPrefix="CT" %>

at the top of your ASP file and

<CT:ClickTale ID="ClickTale" runat="server" />

right before your </body> tag.

Summary

This add-on will allow ClickTale to impersonate the original visitor when caching the content. Implementing this process might have side effects on your site if you perform actions on GET requests. For example, if you keep a counter in your Session object which you raise for every page visit then you will now be getting an additional visit for every page that ClickTale is going to record. Generally you shouldn't have any such cases, but if you do you should check if ClickTale is making the request or a real person and handle properly. You can check that by looking for "ClickTale" in the UserAgent of the request.

Personal tools