Radioactivity
The Radioactivity module provides the site builder with a topical metric for popularity of selected content. Its metric is based upon the number of views the content receives, but it also allows views to “decay”, so that to appear at the top of the list, the content must also have been viewed recently.
Table of contents
Drupal modules discussed in this chapter: Radioactivity, Views.
Introduction
Radioactivity lets you track any fieldable entities: users, nodes, commerce products, etc. It can be used as a simple view counter but also as an activity meter (i.e. you can create a list of the most viewed nodes at this moment.
View incidents are stored as soon as they happen, but energy is only computed during cron runs.
Installing and configuring the module
You install Radioactivity and Views as you would any contributed module. Enable Radioactivity, Views and Views UI.
To make the module do anything, we need to add three things:
- A decay profile
- A radioactivity field
- A view
Adding a decay profile
When you navigate to
, you'll see two tabs: and . You start configuring the by creating a decay profile under the Listadd. To add a new decay profile, click on the link.The initial display shows the following available settings:
- Incident storage: How the energy level changes will be written and stored.
- Profile mode, which is how the articles will gain and lose popularity.
- Time period, the amount of time you set for the decay of item views.
For Incident storage, three options exist:
- Live storage: Incidents are written to the database and the field updated as soon as they happen.
- Deferred storage: Incidents are written to the database but they are only processed and the field updated on cron runs.
- File storage: Incidents are written to a temorary file they are only processed and the field updated on cron runs.
For Incident storage, only the file storage option does not require Drupal to bootstrap.
For Profile mode, three options exist:
- Simple: No decay. It works like a simple counter.
- Basic: Lets you choose the time period an item should need to fall to the bottom, from six hours to a month.
- Advanced: Gives you more fine grained control over the decay.
For the Time period setting, a rule of thumb is that a website that is is seldom updated, or one that see little traffic, should use a long time period. A website with frequent updates with a lot of visitors should use a much shorter time period.
For the first setup of the module, you want to keep the all the default settings (live storage, basic mode, and six hours time period). You can always change this later.
If you choose the advanced profile mode, you even have the option to set granularity. Setting a fine granularity does not affect total decay time, but affects how often the energy level is recomputed and saved. Be aware that for a site with a large number of tracked items, fine granularity can affect performance because it will require more frequent writing to the database or file system.
The figure above shows the decay pattern for a two different profiles. Both has a half life of 12 hours (43200 seconds). However, the top profile has a granularity of 5 minutes (300 seconds), while the bottom profile has a granularity of 2 hours (7200 seconds). Note that in the middle of the graph you see a new emit.
Setting up
When you click on the
tab, you'll see several settings. There are two important parts on the Radioactivity settings page:- Security
- Configuration assist
To prevent 3rd parties from manipulating the field energies with scripts/bots, you should choose a good random string (a salt) used in calculating the checksums for the ajax callbacks.
You also need to set up the radioactivity configuration file:
radioactivity-boostrap.cfg.inc
. This file holds all the required
settings for the callback script to work without drupal and this is
important for high traffic sites; If the file is missing the callback
script does a partial drupal bootstrap so that it can function
properly. Note that Live and Deferred storage types require drupal to
bootstrap while the experimental File storage does not (non-boostrap
memcache support is under development).
Adding a radioactivity field
When a user views the radioactivity field attached to an entity, it generates an incident with an ajax callback which increments that field's energy. This means that the radioactivity field must be added to all entities where you want to track with this module.
To add this field to a content type, navigate to
. Click on the -link for first content type you want to add this field to. Create a new Radioactivity field. Once you have clicked "Save" you are taken to the tab (which is, and should remain, empty). Click on theGo back to the
-page and click on the link. Here we can configure the way the field works by clicking at the cogwheel--icon for the Radioactivity fieldWe can set the amount of View incident energy per view (or disable it by setting this to 0). The following options for how to display the amount of energy the field holds exist:
- Do not display energy
- Raw numeric value
- Percentage
- Hotness gauge
- History
If you don't want to display this value to users, select “Do not display energy”.
For the Teaser display, you do not want somebody viewing all the teasers on the front page to boost the energy of the entity, so make sure the Radioactivity field is hidden.
Adding a view
[TBA - until then: http://www.wunderkraut.com/blog/radioactivity-2-basics/2011-12-05
If you display the radioactivity field in the view, make sure you set "Views incident energy" to 0 to avoid boosting its energy every time the list of most popular posts are shown.
Updating Radioactivity
If you use use drush to download a new version of Radioactivity from Drupal.org,
the file radioactivity-boostrap.cfg.inc
will disappear. It is simple enough to
regenerate from Configuration assist, but you may also want to back it up:
# mv radioactivity/ radioactivity_backup/ # drush dl radioactivity # cp radioactivity_backup/radioactivity-boostrap.cfg.inc radioactivity/
Final word
[TBA]
Last update: 2015-05-14 for D7 [gh].