Radioactivity

by Gisle Hannemyr

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:

  1. A decay profile
  2. A radioactivity field
  3. A view

Adding a decay profile

When you navigate to Administration → Structure → Radioactivity, you'll see two tabs: List and Settings. You start configuring the by creating a decay profile under the Listadd. To add a new decay profile, click on the Add link.

The initial display shows the following available settings:

For Incident storage, three options exist:

For Incident storage, only the file storage option does not require Drupal to bootstrap.

For Profile mode, three options exist:

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.

radioactivity01.png

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 Settings tab, you'll see several settings. There are two important parts on the Radioactivity settings page:

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 Administration → Structure → Content types. Click on the manage fields-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 Field settings tab (which is, and should remain, empty). Click on the Edit tab. On this page select the Decay profile we just created (since there is only one profile it is automatically selected) and add a default value for the energy field. You may set this to 0 if you don't want to boost newly created content, or some higher value if you want to give new content some extra attention.

Go back to the Content types-page and click on the manage display link. Here we can configure the way the field works by clicking at the cogwheel--icon for the Radioactivity field

radioactivity03.png

We 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:

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].