The notion of *popularity* was introduced in SPIP 1.4.

## How to count up visits

There are hundreds of statistical methods to count up visits to a given site. Most methods provide hourly, or daily curves, letting you know if site visits are increasing or decreasing, and to check if there are more people in the early evening and on weekdays than at weekends or during the night...

Our aim, however, is a bit different: we want to give every article a “popularity” value which will quickly reflect a trend, and make it possible to compare the activity of different articles, either in a general way on the entire site (as in charts), or within a section, or among the articles by the same author, and so on.

The method that was decided on is as follows (don’t worry, you can skip this explanation if maths aren’t your favourite subject!):

- each time an article is visited it gets a certain number of points. 1 point if this article’s viewed from the site itself after following a link, and 2 points if it’s a direct visit from an external site (through an engine search, a hypertext link, syndication etc.);

- every ten minutes the resulting score is multiplied by a small discount factor, which means a point given on a visit on Wednesday, at 10:12 am, is worth only half a point the following day at the same time, and a quarter of a point on Friday, at 10:12 am.;

- the whole thing is calculated in such a way that in the case of an article always getting the same *x* number of visits by time units, its score will soon settle at that *x* value. In other words, if the level of requests for an article is stable, the popularity of the article will come to reflect the exact number of daily visits (with an adjustment made for the double score given for the direct visits);

- popularity is expressed in two ways: one, “absolute popularity” (popularite_absolue), expresses the score in question (the number of daily requests for this article); the other, “relative popularity” (popularite_relative), expresses the article’s popularity as a percentage of the absolute popularity of the site’s most popular (popularite_max) article;

- finally the sum of all the absolute popularity scores of the site provides the site’s popularity (popularite_site), making it possible to compare two SPIP-driven sites in terms of the number of visits they receive.

## Loops and tags

Some tags enables you to fetch and display these values in your templates. The following loop sums up all these tags:

The most useful tag is ** #POPULARITE** since it gives a percentage reflecting an article’s popularity in comparison with the most popular article on the site. This allows the easy creation of charts that can be grasped by everyone (with values from 0 to 100). The rest of the tags provide absolute values that the site’s visitors would find more difficult to interpret.

Note:though the data is represented as real numbers in SPIP’s data base, all these tags will always be rounded to a whole number, which will give in rather strange results like this, onvery infrequentlyvisited sites (such as test sites):“This article has an absolute popularity equal to 1, or 17% of 2. In total, this site has approximately 5 visits a day.”

Finally, the ** {par popularite}** sorting criterion can be handy. For example, it can be used in the following way to display the list of the ten most popular articles in the current section:

(Remove `{id_rubrique}`

to display the articles highest up in the charts for the entire site.)