5 votes

Visit Counter

Page Visit Counter

Umbraco 7.3.1+

Is a statistics counter for individual pages

Has a simple label property editor that shows how many times the page has been visited.

It creates a macro, macro partial view, and a data type.

Add the data type to your document type, add the macro to the template, and start counting

Feedback is appreciated

This package saves the node everytime it is visited, to increase the counter, so, per Sebastiaan Janssen's suggestion:

 "please only use this package on very low traffic websites which you don't expect to grow above a few dozen visits a day"

Currently it has english and portuguese localizations

 

Follow these instructions:

  1. Install the Package (Developer > Packages)
  2. Add the DataType to your DocumentType
  3. Add the Macro to the template page
  4. Every time the page is visited, the counter adds up
Notice that this plugin was developed to simply count the visits, not publish them. In case you need to actually publish the count so you can display it somewhere in your site, please change the macro accordingly (see below):

Macro: (you can paste it over the current code)

@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var id = CurrentPage.Id;
var service = ApplicationContext.Current.Services.ContentService;
var content = service.GetById(id);

if(content.HasProperty("visitCounter")){
if(content.GetValue("visitCounter")==null){
content.SetValue("visitCounter",0);
service.Publish(content);
}

else{
content.SetValue("visitCounter",content.GetValue("visitCounter")+1);
service.Publish(content);
}
}
}


To display the code, use the following logic (example)

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = null;
int visits = int.Parse(Umbraco.Field("visitCounter").ToString());
}
<h1>This is the home</h1>
<strong>Visited: @visits</strong>

To start counting, add the macro to the page you intent do track, (and the property in the document type)
        @Umbraco.RenderMacro("VisitCounter")

This is a simple macro, if you have massive traffic, publishing constantly may have side effects. The plan is making a new visit counter that does not publish it to the page, which will be available soon.

Screenshots

Package owner

Carlos Casalicchio

Carlos Casalicchio

Carlos has 479 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud

You must login before you can report on package compatibility.

Previously reported to work on versions:

Package Information

  • Package owner: Carlos Casalicchio
  • Created: 28/06/2016
  • Current version 1.1.2
  • License MIT
  • Downloads on Our: 721

External resources