Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pasang Tamang 258 posts 458 karma points
    Mar 23, 2011 @ 06:20
    Pasang Tamang
    0

    Listing Most Visited Page

    Hello,

    Is there any xslt example to get list of 10 most visited page in umbraco site?

    Thank you for your help

    Pnima

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 23, 2011 @ 23:42
    Chriztian Steinmeier
    0

    Hi Pnima,

    I'm not aware of Umbraco tracking this in any way, so I guess you're out of luck trying to do this from within XSLT.

    If you're using Google Analytics for tracking usage on the site you might be able to embed some kind of report using their API?

    /Chriztian

  • Pasang Tamang 258 posts 458 karma points
    Mar 24, 2011 @ 09:35
    Pasang Tamang
    0

    Finally I solved it and sharing what I did. I create a property "visit" (data type is label) with each document type and did c# function in xslt file which will update the value of "visit" on every page load. Here is the code

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:visitTrack="urn:visitTrack"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <xsl:variable name="pageId" select="$currentPage/@id"/>
    <xsl:value-of select="visitTrack:updateVisit($pageId)"/>
    </xsl:template>
    <msxml:script language="C#" implements-prefix="visitTrack">
        <msxml:assembly href="../bin/cms.dll" />
        <msxml:assembly href="../bin/umbraco.dll" />
        <msxml:assembly href="../bin/businesslogic.dll" />
        <msxml:using namespace="umbraco.BusinessLogic" />
        <msxml:using namespace="umbraco.cms.businesslogic.web" />
        <msxml:using namespace="umbraco.cms.businesslogic.web" />
        public static string updateVisit(int pageId)
        {
    User author = User.GetUser(0); 
    Document doc = new Document(pageId);
    int getCount=int.Parse(doc.getProperty("visit").Value.ToString()) + 1;
    doc.getProperty("visit").Value = getCount.ToString();
    doc.Publish(author);
    umbraco.library.UpdateDocumentCache(doc.Id);
         return getCount.ToString();
        }
      </msxml:script>

    </xsl:stylesheet>

    Further improvement is most welcome

    Thanks

  • Rich Green 2246 posts 4008 karma points
    Mar 24, 2011 @ 09:44
    Rich Green
    0

    Hi,

    Though in theory this should work, be aware that your code will update the database on every visit.

    I'm not sure updating the document cache on every page visit is going to be a good idea in terms of performance at all... 

    If you are updating a database you might as well write to a custom table and just retrieve this value when needed, or even just write to the file system.

    I would strongly consider using Google Analytics API as Chriztian mentioned.

    Regards,

    Rich 

  • Pasang Tamang 258 posts 458 karma points
    Mar 24, 2011 @ 09:51
    Pasang Tamang
    0

    Hi Rich,

    Thanks for alerting me. I'll look on that too.

  • Hugh Abbott 4 posts 23 karma points
    Aug 08, 2011 @ 17:47
    Hugh Abbott
    0

    Pasang, could you get in touch with me about a possible project.

     

    thanks - hugh

     

Please Sign in or register to post replies

Write your reply to:

Draft