Wednesday, October 24, 2012

Image load Tracking in Google Analytics


Image tracking is provided by default with GA, to achieve this we can use Event Tracking for images.


Example:
So if you have an image “Mritunjay.jpg”

<img src="images/Mritunjay.jpg" />
<img src="images/Mritunjay.jpg" onload="_gaq.push(['_trackEvent','Image Tracking','Mritunjay']);" />


‘Image Tracking’ represents the Category
‘Mritunjay’ represents the Action

Thursday, October 18, 2012

Code Blocks are not allowed in this file - Performance Point part 2

As discussed in the previous post how we can fix the Code block error for performance Point, now lets find the reason why the error occurs on the PPSample.aspx and how we can eliminate it at the time of writing the Feature for Masterpage.

The main reason for this error is the the page is updated with the property "customized" this can be checked by the file property "CustomizedPageStatus" in the document library.


following is the code to check if the file is customized/unghosted.

void WriteCustomizedAndNone(object sender, EventArgs e)
        {
            string myResult = '';
            string myListName = txt1.Text;
            SPList myList = SPContext.Current.Web.Site.RootWeb.Lists[myListName];
            if (!Directory.Exists('C:\\Unghosted Files\\'))
            {
                Directory.CreateDirectory('C:\\Unghosted Files\\');
            }
            myResult += 'Status of items<br><br>';
            myResult += '<table style='border:solid 1px gray;'>';
            myResult += '<tr>' + '<td>' + 'Name' + '</td>' + '<td>' + 'Setup Path' + '</td>' + '<td>' + 'is customized' + '</td>' + '</tr>';
            foreach (SPListItem anItem in myList.Items)
            {
                myResult += '<tr>' + '<td >' + anItem.Name + '</td>' + '<td >' + anItem.File.Properties['vti_setuppath'] + '</td>'  + '<td>' + anItem.File.CustomizedPageStatus + '</td>' + '</tr>';
                if (anItem.File.CustomizedPageStatus.ToString() != 'Uncustomized')
                {
                    byte[] myBytes = anItem.File.OpenBinary();
                    System.IO.File.WriteAllBytes('c:\\Unghosted Files\\' + anItem.File.Name, myBytes);
                }
            }
            myResult += '</table>';
            result.Text = myResult;
        }/*Thanks to my friend Siva for this code*/


Note: The page gets updated with the property with Customized if there is any update happens on the page after/during the feature activation, make sure there is no changes happening during the feature activation. 

Any change in the master page will result in UnGhosting which will update the file property to "Customized" and will result in the issue with Performance point "Code Blocks are not allowed in this file".




Wednesday, October 3, 2012

Code Blocks are not allowed in this file - Performance Point



After the customization of the master page in SharePoint 2010, we sometimes get the following error
"Code Blocks are not allowed in this file"

There are two solution for this
1. Add the Page Parser Path in web.config
<PageParserPaths>
       <PageParserPath VirtualPath="/BICenter/Pages/ppssample.aspx" CompilationMode="Always" AllowServerSideScript="true" />
     </PageParserPaths>

2. Modify the PerformancePoint site template by updating the /BICenter/Pages/ppssample.aspx

Replace the following
var siteCollection = "<%=SPHttpUtility.UrlPathEncode(siteCol.Value,false,true)%>";
var siteLocation = "<%=SPHttpUtility.UrlPathEncode(site.Value,false,true)%>";

with
var siteCollection = "/";
var siteLocation = "/BICenter/";