Pages

Showing posts with label MOSS 2007. Show all posts
Showing posts with label MOSS 2007. Show all posts

Tuesday, December 28, 2010

Google Analytics on SharePoint

Seeing the title we might feel that what is the big deal in using Google Analytics on SharePoint content management sites, yes we can get the page views by just embedding few lines of code provided by Google Analytics site.

In the Current implementation we went with a different approach for providing flexibility to Content Authors to manage the Custom Variables, Events and so on...

At a high level following image shows you the flow:



At a high level we used following components in SharePoint which are the inputs to Google Analytics APIs

1. Custom Site Columns

There a set of site columns created for the publishing pages. Few of them are grouped with the group name called "MetaTagGroup". All the columns which are part of this group will be converted to Metatags.

We used a delegate control in SharePoint for generating these meta tags. For more info you can refer to the article on Meta tag generator

Following image shows the set of custom Site Columns mapped to MetaTagGroup



Now the content author has a flexibility to define the values for these Site Columns or Publishing page attribute which inturn converted Meta Tags and then passed to Google Analytics variables as explained in the next step.

2. Additional javascript layer on Google Analytics APIs

An additional javascript functions are created to call respective Google Analytics APIs. And also this javascript contains an array to map Meta tag name with the GA variables, Scope and their slots as shown below:

var arrGAVariables = [
{'GAVariable':'Segment-Type', 'MetaTagName':'Segment-Type', 'Scope':3, 'Slot':3},
{'GAVariable':'Target-Audience', 'MetaTagName':'Target-Audience', 'Scope':1, 'Slot':1},
{'GAVariable':'Business-Technology', 'MetaTagName':'Business-Technology', 'Scope':3, 'Slot':4}
];

Please feel free to contact me to get more insights on this implementation.

Tuesday, August 4, 2009

JQuery to Build Fusion Charts for SharePoint List

This is very much similar to my earlier post "Fusion Charts for SharePoint List" where we used JavaScript for extracting the data from SharePoint List.

Here I will be explaining the similar concept using JQuery. As everyone aware that JQuery is getting very famous and even Microsoft announced that JQuery will be available as part of the Visual Studio 2010 with intellisence too.

Most of the times our customers expect to develop the charts with no time for preparing lots of dashboards or metrics. Lets consider that we have a Task List with all the tasks assigned to different users and are at the different status like:

1. Not Started
2. In Progress
3. Completed
4. Deferred
5. Waiting for someone else

At this point of time we may get lots of request for building the charts for this list data. I will be concentrating on generating the Pie Chart for Different Status available in this Task List, to identify how many tasks are there at different statuses. Following is the sample image showing the List Data:



Following are the steps to implement the fusion charts:
1. Download Fusion Charts and upload to a document library. In this case I created a separate document library called FusionCharts where all the fusion charts are uploaded.
2. Come up with the RPC Protocol URL for extracting the data from the task list.
In our case following is the URL:

http://localhost/sites/MOSSDemos/_vti_bin/owssvr.dll?Cmd=Display&Query=Status&List=%7B7C6C7072%2D12B5%2D4B05%2D90A4%2D052160CC8F74%7D&XMLDATA=TRUE


Note that we are extracting only the Status field from the Task List.
And the List id is the Task List Guiid within the SharePoint Site.

3. Download JQuery script from the site and upload to the Shared Documents.

4. Copy the following javascript which uses JQuery Script into the content editor web part:

<!-- JScript from shared documents -->
<script type="text/javascript" src="/Shared Documents/jquery-1.3.2.min.js"></script>

<!-- Div tag for appending the graph -->
<div id="divGraph"></div>

<script type="text/javascript">

// Declare all local variables
var iNotStarted = 0;
var iInProgress = 0;
var iCompleted = 0;
var iDeferred = 0;
var iWaitingonsomeoneelse = 0;
var sObjectData = "";

// Call the function once the document is loaded
$(document).ready(function() {

var sSiteUrl = "http://localhost/sites/MOSSDemos/_vti_bin/owssvr.dll?";

// This Parameter Contains List Id too
var sCmdParameters = "Cmd=Display&Query=Status&List=%7B7C6C7072%2D12B5%2D4B05%2D90A4%2D052160CC8F74%7D&XMLDATA=TRUE"


// Ajax call using a JavaScript
$.ajax({
url: sSiteUrl + sCmdParameters,
type: "GET",
dataType: "xml",
data: "",
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});

});



function processResult(xData, status) {

//alert(xData.responseXML.xml);


var NS = '#RowsetSchema'
$(xData.responseXML).children(1).children(1).children().each(function() {

var Status = $(this).attr("ows_Status");

switch (Status) {
case "Not Started":
iNotStarted = iNotStarted + 1; break;
case "In Progress":
iInProgress = iInProgress + 1; break;
case "Completed":
iCompleted = iCompleted + 1; break;
case "Deferred":
iDeferred = iDeferred + 1; break;
case "Waiting on someone else":
iWaitingonsomeoneelse = iWaitingonsomeoneelse + 1; break;
default:
break;
}

});

// Create the Object for the Fusion Chart
// Opening Object Tag
sObjectData = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ";
sObjectData += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ";
sObjectData += "width=\"400\" ";
sObjectData += "height=\"300\" ";
sObjectData += "id=\"Pie3D\"> ";

// Setting Parameters
sObjectData += "<param name=\"movie\" value=\"http://localhost/sites/MOSSDemos/FusionCharts/FusionCharts/FCF_Pie3D.swf?chartWidth=400&chartHeight=300\"> ";
sObjectData += "<param name=\"FlashVars\" value=\"&dataXML=<graph caption='Tasks By Status Percentage' ";
sObjectData += "xAxisName='Site' yAxisName='Qty by Site' showNames='1' decimalPrecision='1' showPercentageInLabel='1' formatNumberScale='0' ";
sObjectData += "pieYScale='70' pieBorderAlpha='40' pieFillAlpha='80' pieSliceDepth='15'> ";
sObjectData += "<set name='Not Started' value='" + iNotStarted + "' color='#660033' link='' /> ";
sObjectData += "<set name='Completed' value='" + iInProgress + "' color='#3399ff' link='' /> ";
sObjectData += "<set name='In Progress' value='" + iCompleted + "' color='#99cc99' link='' /> ";
sObjectData += "<set name='Deferred' value='" + iDeferred + "' color='#00ff99' link='' /> ";
sObjectData += "<set name='Waiting for someone else' value='" + iWaitingonsomeoneelse + "' color='#000033' link='' /> ";
sObjectData += "</graph>\"> ";
sObjectData += "<param name=\"quality\" value=\"high\"> ";
sObjectData += "</object> ";


$("#divGraph").append(sObjectData);

}

</script>

Following are the lines to be changed in the script:
A. Location of the FCF_Pie3D.swf file within the "object" tag.
B. Site Url in the variable "sSiteUrl".
C. Task List Id in the variable "sCmdParameters".
D. Path of the JScript (Assumed it is available in the Shared Documents)

With this, A Pie chart representations the Task Data within the SharePoint List as shown below:

Wednesday, July 22, 2009

Fusion Charts for SharePoint List

Most of the time when ever we have data, end users will expect some kind of reports/charts.

For example when we are using tasks, we may have to provide a pie chart indicating the different status in the pie chart. Or We may have to show a visual indicator for the percentage completion for each task item.

We can create the charts by using any of the tools on MOSS 2007:

1. Excel Services (Excel Web Access)
2. Reporting Services
3. Silver Light, etc

In order to use these features we should have MOSS 2007 License and also some environments there will be restrictions on custom coding. By keeping this points in mind I came up with this Post.

Here we will see how we can utilize the Fusion Charts for the SharePoint List (Task List). Following image shows the sample Task List:



Following are the steps to implement the fusion charts:
1. Download Fusion Charts and upload to a document library. In this case I created a separate document library called FusionCharts where all the fusion charts are uploaded.
2. Come up with the RPC Protocol URL for extracting the data from the task list.
In our case following is the URL:

http://localhost/sites/MOSSDemos/_vti_bin/owssvr.dll?Cmd=Display&Query=Status&List=%7B7C6C7072%2D12B5%2D4B05%2D90A4%2D052160CC8F74%7D&XMLDATA=TRUE


Note that we are extracting only the Status field from the Task List.
And the List id is the Task List Guiid within the SharePoint Site.

3. Copy the following javascript into the content editor web part:

<script language="javascript">

function fnXmlHttp(AspFileName,strXML)
{
var objXMLHttp= new ActiveXObject("Microsoft.XMLHTTP");
var sResponse;
try
{
objXMLHttp.open("POST",AspFileName,false) //POSTING THE DATA
objXMLHttp.setRequestHeader("Content-Type", "text/xml");
objXMLHttp.send(strXML)
}
catch(e)
{
}
if (parseInt(objXMLHttp.Status) != 200)
{
sResponse = "N,Cannot connect to the Server.";
}
else
{
sResponse=new String(objXMLHttp.responseText);
if (sResponse == "")
{
sResponse = "N,Error at server. Please contact administrator.";
}
}
return sResponse;

}


var sXML;
var bLoad;

var sSiteUrl = "http://localhost/sites/MOSSDemos/_vti_bin/owssvr.dll?";

// This Parameter Contains List Id too
var sCmdParameters = "Cmd=Display&Query=Status&List=%7B7C6C7072%2D12B5%2D4B05%2D90A4%2D052160CC8F74%7D&XMLDATA=TRUE"

// Request the RPC Call
sXML = fnXmlHttp(sSiteUrl + sCmdParameters,"");

// Create the XML Object Instance
var objXML = new ActiveXObject("MSXML2.DOMDocument");

// Load the XML
bLoad = objXML.loadXML(sXML);

// Check whether the XML is loaded into the document
if(bLoad)
{
// Declare all local variables
var iNotStarted = 0;
var iInProgress = 0;
var iCompleted = 0;
var iDeferred = 0;
var iWaitingonsomeoneelse = 0;
var sObjectData;

var objData = objXML.documentElement.childNodes(1);

// Loop through all the variables
for (i=0;i<objData.childNodes.length;i++)
{
var Status = objData.childNodes(i).attributes.getNamedItem("ows_Status").value;

switch(Status)
{
case "Not Started":
iNotStarted = iNotStarted + 1; break;
case "In Progress":
iInProgress = iInProgress + 1; break;
case "Completed":
iCompleted = iCompleted + 1; break;
case "Deferred":
iDeferred = iDeferred + 1; break;
case "Waiting on someone else":
iWaitingonsomeoneelse = iWaitingonsomeoneelse + 1; break;
default:
break;
}

}

// Create the Object for the Fusion Chart
// Opening Object Tag
sObjectData = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ";
sObjectData += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ";
sObjectData += "width=\"400\" ";
sObjectData += "height=\"300\" ";
sObjectData += "id=\"Pie3D\"> ";

// Setting Parameters
sObjectData += "<param name=\"movie\" value=\"http://localhost/sites/MOSSDemos/FusionCharts/FusionCharts/FCF_Pie3D.swf?chartWidth=400&chartHeight=300\"> ";
sObjectData += "<param name=\"FlashVars\" value=\"&dataXML=<graph caption='Tasks By Status Percentage' ";
sObjectData += "xAxisName='Site' yAxisName='Qty by Site' showNames='1' decimalPrecision='1' showPercentageInLabel='1' formatNumberScale='0' ";
sObjectData += "pieYScale='70' pieBorderAlpha='40' pieFillAlpha='80' pieSliceDepth='15'> ";
sObjectData += "<set name='Not Started' value='" + iNotStarted + "' color='#660033' link='' /> ";
sObjectData += "<set name='Completed' value='" + iInProgress + "' color='#3399ff' link='' /> ";
sObjectData += "<set name='In Progress' value='" + iCompleted + "' color='#99cc99' link='' /> ";
sObjectData += "<set name='Deferred' value='" + iDeferred + "' color='#00ff99' link='' /> ";
sObjectData += "<set name='Waiting for someone else' value='" + iWaitingonsomeoneelse + "' color='#000033' link='' /> ";
sObjectData += "</graph>\"> ";
sObjectData += "<param name=\"quality\" value=\"high\"> ";
sObjectData += "</object> ";
document.write(sObjectData);
}


</script>

Following are the lines to be changed in the script:
A. Location of the FCF_Pie3D.swf file within the "object" tag.
B. Site Url in the variable "sSiteUrl".
C. Task List Id in the variable "sCmdParameters".

With this, A Pie chart representations the Task Data within the SharePoint List as shown below:

Tuesday, July 21, 2009

SharePoint List Data Access

In this post we will see what are the different ways that we extract the data from the SharePoint List at a higher and this will be the basic for the future posts. List can be a Custom List, Document Library, or Survey.

Following are the different ways of accessing data from a list at a broad level:

1. Using Object Model

2. Using Web Services

3. Using Remote Procedure Calls

SharePoint Object Model
There are rich set of APIs for accessing the SharePoint List. Most of the times we will be using following objects:

A. SPSite -> Represents Site Collection
B. SPWeb -> Represents a Web (which is a sub site)
C. SPList -> Represents a List (Can be a Custom List/Document Library etc)
D. SPListItem -> Represents an Item in a List

Apart from these classes we may be using SPFolder, SPFile, etc classes too.
More info is available @ SharePoint Object Model

Please note that we will be using the SharePoint Object in the custom applications/Web Parts which will be hosting on the Same SharePoint Servers.

Web Services
The other approach of accessing the data using sharepoint web services.
For example we can use Lists.asmx for accessing the data from a List.

Like this we have lots of web services for accessing the data from SharePoint. You can get list of web services @ List of SharePoint Web Services

Since it is a web service, we can use in any custom applications and it can be hosted on SharePoint Server or any other server.

Using Remote Procedure Calls
From SharePoint 2003, we have one more approach for accesing the sharepoint data using RPC Protocal.
Following is the syntax:

http://Server_Name/[sites/][Site_Name/]_vti_bin/owssvr.dll?Cmd=
Method_name[&Parameter1=Value1&Parameter2=Value2...]

Here we are just providing the method and parameters to query the sharepoint database. For example if we want to access the sharepoint task list we can provide the following URL:

http://localhost/sites/DemoSite/_vti_bin/owssvr.dll?Cmd=Display&List=%7B2E5E526D%2D993C%2D45B9%2DAF0F%2DDE71F8985220%7D&XMLDATA=TRUE&Query=*

In the url, we are specifying the following parameters:

Method Name: Display -> For fetching the data
Parameter: List -> For providing the List Id (GUID)
Parameter: XMLDATA -> For extracting data in the xml format
Parameter: Query -> To provide list of column names separated by the space. * indicates all the columns.

You can get complete list of commands and their parameters @ URL Protocol

This post is the basics for the upcoming post on Displaying Data in a graphical format as shown below: