Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 04, 2012 @ 15:00
    Fuji Kusaka
    0

    Most Viewed Node

    Hi All,

    Is it possible to make display a list of "Most Viewed Node" in Umbraco With XSLT or Razor??

     

    //fuji

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 04, 2012 @ 15:19
    Lee Kelleher
    0

    Hi Fuji,

    There isn't anything out-of-the-box to do this with Umbraco, you'll need to implement it yourself.

    I generally use Google Analytics for page-views/stats ... I have rolled my own view-counter, but it's not the best example of what to do... for each page load I was incrementing a counter in a node/document's property. Which had to be republished to be used ... so each page-reload was a republish, not very good for performance! (I do not recommend doing this)

     

    Quick google search found these:

    http://stackoverflow.com/questions/6627673/umbraco-cms-how-to-make-a-hit-counter

    http://refactored.com.au/blog/2011/11/14/introducing-the-umbraco-view-counter/

     

    Cheers, Lee.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 04, 2012 @ 15:20
    Lee Kelleher
    0

    Ah ha, noticed that the second link, has a package available: Refactored's Content Views

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 04, 2012 @ 15:24
    Fuji Kusaka
    0

    Hi Lee,

    Thanks for the links. I will be considering the second link dont think having i will be using the Google Analytics since i need a counter for a Most Viewed Article in an Intranet System.

    //fuji 

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 05, 2012 @ 07:15
    Robert Foster
    0

    Hi Fuji,

    The following xslt example will sort based on the number of views:

    <?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:umbraco.library="urn:umbraco.library"
      xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
      xmlns:ViewCount="urn:ViewCount"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon ViewCount ">


      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>

      <xsl:template match="/">
        <ul>
          <xsl:for-each select="$currentPage//* [@isDoc ]">
            <xsl:sort select="ViewCount:GetViews(number(@id))//@count" order="descending"  data-type="number"/>
            <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" />
            <li>
              Node: <xsl:value-of select="$counter//@nodeId" /><br />
              Count: <xsl:value-of select="$counter//@count" /><br />
              Last Viewed: <xsl:value-of select="$counter//@lastViewed" /><br />
              Category: <xsl:value-of select="$counter//@category" /><br />
              Hide Counter: <xsl:value-of select="$counter//@hideCounter" /><br />
              Enable History: <xsl:value-of select="$counter//@enableHistory" />
            </li>
          </xsl:for-each>
        </ul>
      </xsl:template>

    </xsl:stylesheet>

    The key is the data-type="number" attribute on the xsl:sort element... It is missing from the example in the package.

    Let me know how you go,

    Rob.

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 07:51
    Fuji Kusaka
    0

    Hi Robert,

    I try  the xslt but its not working though. Also i added the View Count Datatype to my Document Type but still the Count remains "0 View".

    I instead change the xslt to 

    <xsl:for-each select="$currentPage">
            <xsl:sort select="ViewCount:GetViews(number(@id))//@count" order="descending"/>
            <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" />
            <li>
              Node: <xsl:value-of select="$counter//@nodeId" /><br />
              Count: <xsl:value-of select="$counter//@count" /><br />
              Last Viewed: <xsl:value-of select="$counter//@lastViewed" /><br />
              Category: <xsl:value-of select="$counter//@category" /><br />
              hide Counter: <xsl:value-of select="$counter//@hideCounter" /><br />
              enable History: <xsl:value-of select="$counter//@enableHistory" />
            </li>
          </xsl:for-each>

     

    Just to get the number of count for the currentPage but still no output only NodeId displayed.

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 08:17
    Fuji Kusaka
    0

    Any thought what i might be doing wrong??

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 08:41
    Fuji Kusaka
    0

    This is my output...

    Node: 1497
    Count: 0
    Last Viewed: 
    Category: 
    hide Counter: 0
    enable History: 0

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 05, 2012 @ 09:37
    Robert Foster
    0

    Hi,

    I assume you've added the View Count datatype to a document type, and have published a few documents based on that document type?  If you refresh one of the published pages, it should update the count.

    You should also be able to see the number of Views on the Document in the backend if you have it setup correctly...

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 10:06
    Fuji Kusaka
    0

    Sitll nothing robert, even in my Backend i still have 0 views.

    Here is how i proceeded. In my datatype View Count  

    Category: number
    Hide View Count: no
    Enable View History: no
    Disable Counter Reset: no

     and in document tpe with type alias "count" and type "view count". and finally my xslt

    <!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: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" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.request="urn:ucomponents.request" xmlns:refactoredExtensions="urn:refactoredExtensions" xmlns:ViewCount="urn:ViewCount" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ucomponents.members ucomponents.request refactoredExtensions ViewCount ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
      
      <ul>
        <xsl:for-each select="$currentPage">
             
            <xsl:sort select="ViewCount:GetViews(number(@id))//@count" order="descending"  data-type="number"/>

            <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" />
            <li>
              Node: <xsl:value-of select="$counter//@nodeId" /><br />
              Count: <xsl:value-of select="$counter//@count" /><br />
              Last Viewed: <xsl:value-of select="$counter//@lastViewed" /><br />
              Category: <xsl:value-of select="$counter//@category" /><br />
              Hide Counter: <xsl:value-of select="$counter//@hideCounter" /><br />
              Enable History: <xsl:value-of select="$counter//@enableHistory" />
            </li>
          </xsl:for-each>
        </ul>

    </xsl:template>

    </xsl:stylesheet>
  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 05, 2012 @ 10:26
    Robert Foster
    0

    Note that if you set a category in your View Counter datatype, you will need to specify that category in the ViewCounter:GetViews() method in XSLT as well.  GetViews has 3 function signatures:

    GetViews(int nodeId)
    
    GetViews(int nodeId, string category)
    
    GetViews(int nodeId, string category, bool increment)
    

    if you leave the category blank in the View Counter Datatype you can just use the first signature as you have in the XSLT example you posted. Otherwise you must use the second or third form.  The increment parameter allows you to increment the viewcount at the same time (it's done prior to the data lookup) - by default this value is false.

    Hope this helps,

    Rob.

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 11:11
    Fuji Kusaka
    0

    Weird am still not getting anything....i left the datatype Category blank and use this in my xslt

    <xsl:sort select="ViewCount:GetViews(number(@id))//@count" order="descending"  data-type="number"/>

      <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" />

    is there something to set in the documentType alias?

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 05, 2012 @ 11:54
    Fuji Kusaka
    100

    It works when i change it to 

     <xsl:sort select="ViewCount:GetViews(number(@id),'View','True')" order="descending"  data-type="number"/>

    Setting the dataType to View.

    //fuji

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 05, 2012 @ 14:05
    Robert Foster
    0

    Hi,

    As you found, you will need to call one of the library methods that increments the view count.  I actually had forgotten that myself, although it's discussed in the blog entry here - http://refactored.com.au/blog/2011/11/14/introducing-the-umbraco-view-counter/

    A few things to note:

    • You could call GetViews(number(@id), '', 1) in your xslt to increment the view counter for a page without specifying a category.
    • You don't have to attach the datatype to a document in order to use the view counter.  Doing so however allows you to see the number of views a document has received.  It also allows you to reset the view count.  If you do use the datatype, make sure the category reflects whatever you use in the xslt library function
    • There is a sample Razor Script supplied with the package that you can use to embed in a document template.  This is how I increment my view count on pages.

    Hope this helps.

    Rob.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 05, 2012 @ 14:13
    Robert Foster
    0

    One more thing - the project forums also discuss this topic - you may want to take a look there: http://our.umbraco.org/projects/website-utilities/refactored-content-views/developer-questions/26080-List-of-most-visited-pages

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 06, 2012 @ 06:50
    Fuji Kusaka
    0

    Hi,

    For the time being i will leave the datatype in the document type so as to allow the admin to monitor and see the number of views for a node.

    I will try the razor script as well, good to know both.

    Thanks 

    //fuji

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 06, 2012 @ 11:48
    Fuji Kusaka
    0

    Just to point out when using this

    GetViews(number(@id), '', 1)

    it actually increments by 2 instead of 1

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Apr 07, 2012 @ 09:18
    Robert Foster
    0

    Hi Fuji,

    Yep, I just confirmed this and have uploaded a fix.  Go download version 0.6.1 of the package. Note also that this bug only affects the GetViews method, all of the other library methods are not affected at all.

    Thanks,

    Rob.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 02, 2012 @ 09:59
    Fuji Kusaka
    0

    Hi Robert,

    Am trying to achieve the same thing with media but somehow it returns "0". Just for information i have a macro xslt mediaPicker displaying all recents uploads.

    But now clients would like to get the number of views for each Media item ,so added a new property in the Media Type with Type View Count.

    Any suggestions why this is not working?

    Thanks

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jul 09, 2012 @ 04:16
    Robert Foster
    0

    Hi Fuji,

    Firstly, apologies for not getting back to you sooner, have been interstate for the better part of the past 3 weeks with limited internet access (doing my work using my iPhone tethered to my laptop with remote desktop to my server aint fun)

    The package wasn't designed for use with media - it can be made to, but I need to know more about how you are displaying the media you are wanting to track...

  • anusha 6 posts 26 karma points
    Nov 10, 2012 @ 08:54
    anusha
    0

    How can we find recently visited 3 pages in umbraco can any one help pls?

     

  • umbracocool 108 posts 197 karma points
    May 29, 2013 @ 08:47
    umbracocool
    0

    My bro. Thanks!. What is the Package?

  • Fuji Kusaka 2203 posts 4220 karma points
    May 29, 2013 @ 09:36
    Fuji Kusaka
    0

    Here is the link to the package 

Please Sign in or register to post replies

Write your reply to:

Draft