Webtrends and MOSS

Webtrends and MOSS, How do V do it?Lot of times customer are using Webtrends and they want to integrate the stuff in Sharepoint, so how the H :) we do that. Easy and following are some steps we followed:

Some Details that I gathered for the requirement:

1. Master pages will have a SCRIPT block to add the Webtrends.js file. (Webtrends.js: making a request to SDC server and generates a log file)

2. WEBTRENDS.JS has to be part of each and every MASTER page, as that’s how it will propagate to each content page. Also the JS script should be added at the end of the MASTER PAGE so that it captures all the required tags. The JS file is smart enough to capture only those tags that start with a specific PREFIX, like WBT….this helps as JS file does not capture all the TAGS.

3.  User alias and things like that are captured thru a ASP.net user control that generates the metatag on the page (these meta tags will be picked up by WebTrends.js).

4. http://Tagbuilder.webtrends.com is the site to look at for building the WEBTRENDS.JS file to be included in the MASTERPAGE.

 

 

Some details of our implementation:

 

1.       You need to create the META tags required to be used by the WEBTRENDS, this can be generated from a custom user control and you need to add this User Control on the Master Page. For e.g. we had following entries for our custom control that we created:

a.       <%@ Register TagPrefix="Webtrends" TagName="Control" src="~/_controltemplates/ABCUserControls/WebTrends.ascx" mce_src="~/_controltemplates/ABCUserControls/WebTrends.ascx" %> (just registering the User control on the Master Page)

b.      <Webtrends:Control runat=”server” id=” Webtrends” />  (Very much similar to how you add a welcome or Signout control)

2. You may have to use some kind of Config Store to store the configurtion values (check out Chris O'Brien's config store: www.codeplex.com/SPConfigStore)   

3. A Webtrends Java Script is needed ( The Master Page needs to include the standard WebTrends JavaScript. This script performs the heavy lifting for this solution component, and will be responsible for generating the click stream data by calling the WebTrends servers.).

3. The custom control generates Meta Tags and source code is below (Please note that your implementation of this control would change depending on what kind of meta Tags you need to generate):

 SAMPLE OUTPUT GENERATED by the CONTROL:

<meta name=”SOMESDCAPPID” content=”[Application:SDCAppID]”/>
<meta name=”SDCSERVER” content=”SDCSERVERVALUE”/>
<meta name=”WTPortalDomain” content=”PORTALDOMAINNAME”/>
<meta name=”WTUID” content=”[MOSS:UserIdentifier]”/> 

using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Text;
using COB.SharePoint.Utilities;

namespace Ketaanh.Enterprise.WebTrends
{

    public partial class WebtrendsUserControl : UserControl
{
#region Varible Declaration"
StringBuilder strMetaDataCollections;
const string SEGMENT = "SmeSegMentWeUed";
const string UNIQUE_USER_IDENTIFIE_DCSAUT = "SomeUsrIdntfier";
const string WEB_TRENDS_PORTAL_DOMAIN = "WTPortalDomain";
const string UNIQUE_USER_IDENTIFIE = "WTUsrIDFier";
const string WEB_TRENDS_SDC_SERVER = "WTSDCServerName";
const string WEB_TRENDS_SDC_APPID = "WTSDCAPPID";

        string strUniqueUserIdentifierProfileKey;  

        string strSegmentProfileKey;
string strMainHeadTagId = string.Empty;
string strUniqueUserIdentifier = string.Empty;
string strSegment = string.Empty;
string strWebTrendsSDCAppID = string.Empty;
string strWebTrendsSDCServer = string.Empty;
string strWebTrendsPortalDomain = string.Empty;
string strWebTrendsNoScriptImagePath = string.Empty;
#endregion
# region Override the base Methods

/// <summary>
/// Overriding the existing Method to writer content in UserControl
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
strMetaDataCollections = new StringBuilder();
try
{
string strImgPath = string.Empty;
BuildConfigStoreValues(); //Featching values from config store data
strMetaDataCollections.AppendLine("");// add first blank line
strImgPath = string.Format(strWebTrendsNoScriptImagePath, strWebTrendsSDCServer, strWebTrendsSDCAppID);
ltNoScript.Text = string.Format("<div><img alt=\"DCSIMG\" id=\"DCSIMG\" width=\"1\" height=\"1\" src=\"{0}\"/></div>", strImgPath);
BuildMetaDataTag(WEB_TRENDS_SDC_APPID, strWebTrendsSDCAppID);
BuildMetaDataTag(WEB_TRENDS_SDC_SERVER, strWebTrendsSDCServer);
BuildMetaDataTag(WEB_TRENDS_PORTAL_DOMAIN, strWebTrendsPortalDomain);

                #region "For Authenticated users only"

                if (HttpContext.Current.User.Identity.IsAuthenticated)
{
BuildUserProfilePropertyValues();
BuildMetaDataTag(UNIQUE_USER_IDENTIFIE, strUniqueUserIdentifier);
BuildMetaDataTag(UNIQUE_USER_IDENTIFIE_DCSAUT, strUniqueUserIdentifier);
BuildMetaDataTag(SEGMENT, strSegment);
}
#endregion

                writer.Write(strMetaDataCollections.ToString());
base.Render(writer);
}
catch (Exception ex)
{

}
}
#endregion
#region "Private Method"

#region BuildConfigStoreValues

        /// <summary>
/// Get Config Value
/// </summary>
/// <param name="strCategory"></param>
/// <param name="strKey"></param>
/// <returns></returns>
private string GetConfigValue(string strCategory, string strKey)
{
string strValue = null;
if (!string.IsNullOrEmpty(ConfigStore.GetValue(strCategory, strKey)))
{
strValue = ConfigStore.GetValue(strCategory, strKey);
}
else
{
throw new NullReferenceException(string.Format("{0}:{1}", strCategory, strKey));
}
return strValue;
}
/// <summary>
/// Build All configuration Values
/// </summary>
private void BuildConfigStoreValues()
{
try
{
strUniqueUserIdentifierProfileKey = GetConfigValue("WebTrends", "UniqueUserIdentifierProfileKey");
strSegmentProfileKey = GetConfigValue("WebTrends", "SegmentProfileKey");
strMainHeadTagId = GetConfigValue("WebTrends", "MainHeadTagId");
strWebTrendsSDCAppID = GetConfigValue("WebTrends", "WebTrendsSDCAppID");
strWebTrendsSDCServer = GetConfigValue("WebTrends", "WebTrendsSDCServer");
strWebTrendsPortalDomain = GetConfigValue("WebTrends", "WebTrendsPortalDomain");
strWebTrendsNoScriptImagePath = GetConfigValue("WebTrends", "WebTrendsNoScriptImagePath");
}
catch (Exception ex)
{
                 

            }

        }
#endregion
/// <summary>
/// BuildMetaDataTag
/// </summary>
/// <param name="strName"></param>
/// <param name="strContent"></param>
private void BuildMetaDataTag(string strName, string strContent)
{
if (!string.IsNullOrEmpty(strName) && !string.IsNullOrEmpty(strContent))
{
strMetaDataCollections.AppendLine(string.Format("<meta name=\"{0}\" content=\"{1}\" />", strName, strContent));

            }
else
{ //All Key value should be render
throw new NullReferenceException(string.Format("{0}:{1}", strName, strContent));
}
}
/// <summary>
/// BuildUserProfileProperty from Cookies
/// </summary>
private void BuildUserProfilePropertyValues()
{
string _badgeNumber = string.Empty;

            try
{
strUniqueUserIdentifier = CookieUtility.GetUniqueUserID(); //This is the custom utility we wrote to get the Cookie value it is simple you can implement your own
strSegment = CookieUtility.GetSegment();

}
catch (Exception ex)
{
// exception will be pass to the calling methods
throw ex;

            }

         }

#endregion
}
}