You are here

README.txt in Radioactivity 4.0.x

With the Radioactivity module you can measure popularity of your content. In
combination with Views you can makes lists of popular content.

INSTALLATION
============

Install and enable the module as usual:
https://www.drupal.org/docs/extending-drupal/installing-modules

The Radioactivity module has no dependencies other than Drupal core.

CONFIGURATION
=============

The Radioactivity module provides two field types: Radioactivity and
Radioactivity Reference.

The Radioactivity field stores the energy value as part of the entity to which
the field is added. This is the classic approach. It is technically proven but
has a known problem which prevents editors for saving the node when cron updates
the energy values while the node is being edited.
See https://www.drupal.org/project/radioactivity/issues/3106687

The Radioactivity field will be deprecated in a future release. Use the
Radioactivity Reference field (below) when you start with Radioactivity module.

The Radioactivity Reference field stores the energy value in a separate entity.
It is the new kid on the block, it was introduced in the ...(TODO) release. It
was developed to mitigate the above editorial problem. Although it is
technically an entity reference field, the field itself it manages the
referenced radioactivity entity and only exposes the energy level to the editor.

The Radioactivity (Reference) fields come with two formatters: Emitter and
Value. Use the Emitter formatter only on those places where a view should be
counted (e.g. Full content) and not in lists of content that should not be
measured for popularity. Each instance of the Emitter formatter can be
configured with its own Energy value to emit. E.g. a Full content view can emit
more energy than a search result view. Use the Value formatter to only display
the popularity, e.g. in a backend view without emitting energy (and thus not
count for popularity).

FIELD CONFIGURATION
===================

Each Radioactivity (Reference) field has storage settings that determine how
the popularity is measured and how it behaves over time.

Energy profile
  - Count: Each visit increases the energy value by one. Never decreases.
    Use this profile to count visits.
  - Linear: Energy increases by the emission amount. Decreases the energy value
    by 1 per second.
  - Decay: Energy increases by the emission amount. Decreases the energy value
    by 50% per half-life time (see below).

Granularity
  The minimum time in seconds before energy decay will be re-calculated. Cron
  should run at least one time within this time frame. If for example you want
  the popularity list to be updated daily, the granularity should be 3600 * 24
  seconds or less. A lower Granularity spreads the load of processing decays.
  Set this time to a (very) low value to update on each cron.

Half-life time
  The time in seconds in which the energy decreases by 50%. Start with a high
  value (e.g. 1 week or longer). Create a view in the backend to monitor the
  result and monitor the behaviour over time. Decrease the half-life time to
  better distinguish between old and new. Increase the half-life time if not
  enough nodes have an energy value.

Cutoff
  Energy levels under this value is set to zero. Example: 0.5, 2.
  This value is used limit the number of entities that must be processed.
  Energy values below this threshold are considered to be not relevant for
  popularity. Start with a low value (e.g. 1/10th of a single emission) and
  increase the value to reduce the number of items. For example, you have list
  of the 10 most popular nodes. Set the cut-off value equal to the average
  energy of the item on position 20.

Default energy (field setting)
  The initial energy value when content is created. Use this value to give new
  content an initial (high) ranking in the popularity list. Start with 10 times
  the energy of a single emission (see below) and adjust the value to
  balance new and popular content within the list of popular items.

Energy (Emitter formatter)
  The amount of energy to emit when this field is displayed. Each time the
  content is displayed this value will be added to the energy level. Use a
  simple value such as 1 or 10. On a busy site use 1 on a low traffic site use
  10. If you count popularity using different view modes (e.g. Full content and
  Search result) you can use distinct Energy values to rate each view mode
  differently (e.g. Full content: 10, Search result: 1).

CRON
====

The Radioactivity module uses cron to update the energy values. Only after a
cron job you will see the energy level change. Emissions are processed (energy
increases) and decay is processed (energy decreases). Emissions are processed
on each cron job. Decay is processed after the Granularity time has elapsed.

MULTILINGUAL
============

Only the Radioactivity Reference field supports multilingual. Enable translation
of the field when you want to differentiate the content popularity per language.
Do not enable the translation of the field to use the same popularity value
for each translation of the content.

VIEWS INTEGRATION
=================

Content popularity is typically used to show a list of popular content (either
in the front or in the backend). To create a view of popular nodes:
- Create a list view of nodes
- Add a relationship 'Content using field_name', and require the relationship.
- Sort by descending Energy (Relation: Radioactivity field)

STORAGE
=======

Radioactivity module provides two storages to store the emitted incident data:
in the database (default) or in a file. The Default Storage uses Drupal's
key/value storage in the database. The Rest Storage uses a file in the server's
temporary file directory.

The storage configuration can currently only be altered in settings.php. If you
want to use the default storage, you can skip the section below.

```
// Use the radioactivity Default Storage (database).
$config['radioactivity.storage']['type'] = 'default';
```

```
// Use the radioactivity Rest Storage (file).
$config['radioactivity.storage']['type'] = 'rest_local';
```

The provided rest storage service uses a php executable as endpoint. The
default endpoint is: /path/to/radioactivity/endpoints/file/rest.php. If you
want to run the service under another path (e.g. directly under the root) or on
a different host, you can override the endpoint url:

```
// Use the radioactivity Rest Storage (file) on a custom endpoint.
$config['radioactivity.storage'] = [
    'type' => 'rest_remote',
    'endpoint' => 'http://www.example.com/rest.php',
];
```

NOTE! When using a different host name you may need to set CORS (Cross-origin
resource sharing) for things to work properly.

DEBUGGING
=========

When the energy value does not increase or decrease as you expect, use the
hints below to check.

- Use the Emitter formatter (/admin/structure/types/manage/{node type}/display
  and select the Display 'Energy level + emit' setting. The field will now
  display the current energy value.
- Edit the node and check the Energy value in the field. The value is the same
  as the displayed value in the previous hint.
- When a page is visited a POST request should be fired to
	/radioactivity/emit (default storage) or
 	/path/to/radioactivity/endpoints/file/rest.php (local rest storage)
- Emissions re stored in the database table (default storage)
  `SELECT * FROM `key_value` WHERE `name` = 'radioactivity_incidents';`
  or is in file at /tmp/radioactivity-payload.json (assuming the server
  temporary storage is /tmp)
- Cron reports the Radioactivity processing results. Example
  ```
  drush cron
   ...
   [notice] Processed 2 radioactivity decays.
   [notice] Processed 1 radioactivity incidents.
  ```
  The numbers refer to the number of entities processed, not the individual
  incidents. Unpublished entities also gets counted, but their data is
  not processed (no decay).
  Set the Granularity to 1 to make sure each cron job will update the energy.

File

README.txt
View source
  1. With the Radioactivity module you can measure popularity of your content. In
  2. combination with Views you can makes lists of popular content.
  3. INSTALLATION
  4. ============
  5. Install and enable the module as usual:
  6. https://www.drupal.org/docs/extending-drupal/installing-modules
  7. The Radioactivity module has no dependencies other than Drupal core.
  8. CONFIGURATION
  9. =============
  10. The Radioactivity module provides two field types: Radioactivity and
  11. Radioactivity Reference.
  12. The Radioactivity field stores the energy value as part of the entity to which
  13. the field is added. This is the classic approach. It is technically proven but
  14. has a known problem which prevents editors for saving the node when cron updates
  15. the energy values while the node is being edited.
  16. See https://www.drupal.org/project/radioactivity/issues/3106687
  17. The Radioactivity field will be deprecated in a future release. Use the
  18. Radioactivity Reference field (below) when you start with Radioactivity module.
  19. The Radioactivity Reference field stores the energy value in a separate entity.
  20. It is the new kid on the block, it was introduced in the ...(TODO) release. It
  21. was developed to mitigate the above editorial problem. Although it is
  22. technically an entity reference field, the field itself it manages the
  23. referenced radioactivity entity and only exposes the energy level to the editor.
  24. The Radioactivity (Reference) fields come with two formatters: Emitter and
  25. Value. Use the Emitter formatter only on those places where a view should be
  26. counted (e.g. Full content) and not in lists of content that should not be
  27. measured for popularity. Each instance of the Emitter formatter can be
  28. configured with its own Energy value to emit. E.g. a Full content view can emit
  29. more energy than a search result view. Use the Value formatter to only display
  30. the popularity, e.g. in a backend view without emitting energy (and thus not
  31. count for popularity).
  32. FIELD CONFIGURATION
  33. ===================
  34. Each Radioactivity (Reference) field has storage settings that determine how
  35. the popularity is measured and how it behaves over time.
  36. Energy profile
  37. - Count: Each visit increases the energy value by one. Never decreases.
  38. Use this profile to count visits.
  39. - Linear: Energy increases by the emission amount. Decreases the energy value
  40. by 1 per second.
  41. - Decay: Energy increases by the emission amount. Decreases the energy value
  42. by 50% per half-life time (see below).
  43. Granularity
  44. The minimum time in seconds before energy decay will be re-calculated. Cron
  45. should run at least one time within this time frame. If for example you want
  46. the popularity list to be updated daily, the granularity should be 3600 * 24
  47. seconds or less. A lower Granularity spreads the load of processing decays.
  48. Set this time to a (very) low value to update on each cron.
  49. Half-life time
  50. The time in seconds in which the energy decreases by 50%. Start with a high
  51. value (e.g. 1 week or longer). Create a view in the backend to monitor the
  52. result and monitor the behaviour over time. Decrease the half-life time to
  53. better distinguish between old and new. Increase the half-life time if not
  54. enough nodes have an energy value.
  55. Cutoff
  56. Energy levels under this value is set to zero. Example: 0.5, 2.
  57. This value is used limit the number of entities that must be processed.
  58. Energy values below this threshold are considered to be not relevant for
  59. popularity. Start with a low value (e.g. 1/10th of a single emission) and
  60. increase the value to reduce the number of items. For example, you have list
  61. of the 10 most popular nodes. Set the cut-off value equal to the average
  62. energy of the item on position 20.
  63. Default energy (field setting)
  64. The initial energy value when content is created. Use this value to give new
  65. content an initial (high) ranking in the popularity list. Start with 10 times
  66. the energy of a single emission (see below) and adjust the value to
  67. balance new and popular content within the list of popular items.
  68. Energy (Emitter formatter)
  69. The amount of energy to emit when this field is displayed. Each time the
  70. content is displayed this value will be added to the energy level. Use a
  71. simple value such as 1 or 10. On a busy site use 1 on a low traffic site use
  72. 10. If you count popularity using different view modes (e.g. Full content and
  73. Search result) you can use distinct Energy values to rate each view mode
  74. differently (e.g. Full content: 10, Search result: 1).
  75. CRON
  76. ====
  77. The Radioactivity module uses cron to update the energy values. Only after a
  78. cron job you will see the energy level change. Emissions are processed (energy
  79. increases) and decay is processed (energy decreases). Emissions are processed
  80. on each cron job. Decay is processed after the Granularity time has elapsed.
  81. MULTILINGUAL
  82. ============
  83. Only the Radioactivity Reference field supports multilingual. Enable translation
  84. of the field when you want to differentiate the content popularity per language.
  85. Do not enable the translation of the field to use the same popularity value
  86. for each translation of the content.
  87. VIEWS INTEGRATION
  88. =================
  89. Content popularity is typically used to show a list of popular content (either
  90. in the front or in the backend). To create a view of popular nodes:
  91. - Create a list view of nodes
  92. - Add a relationship 'Content using field_name', and require the relationship.
  93. - Sort by descending Energy (Relation: Radioactivity field)
  94. STORAGE
  95. =======
  96. Radioactivity module provides two storages to store the emitted incident data:
  97. in the database (default) or in a file. The Default Storage uses Drupal's
  98. key/value storage in the database. The Rest Storage uses a file in the server's
  99. temporary file directory.
  100. The storage configuration can currently only be altered in settings.php. If you
  101. want to use the default storage, you can skip the section below.
  102. ```
  103. // Use the radioactivity Default Storage (database).
  104. $config['radioactivity.storage']['type'] = 'default';
  105. ```
  106. ```
  107. // Use the radioactivity Rest Storage (file).
  108. $config['radioactivity.storage']['type'] = 'rest_local';
  109. ```
  110. The provided rest storage service uses a php executable as endpoint. The
  111. default endpoint is: /path/to/radioactivity/endpoints/file/rest.php. If you
  112. want to run the service under another path (e.g. directly under the root) or on
  113. a different host, you can override the endpoint url:
  114. ```
  115. // Use the radioactivity Rest Storage (file) on a custom endpoint.
  116. $config['radioactivity.storage'] = [
  117. 'type' => 'rest_remote',
  118. 'endpoint' => 'http://www.example.com/rest.php',
  119. ];
  120. ```
  121. NOTE! When using a different host name you may need to set CORS (Cross-origin
  122. resource sharing) for things to work properly.
  123. DEBUGGING
  124. =========
  125. When the energy value does not increase or decrease as you expect, use the
  126. hints below to check.
  127. - Use the Emitter formatter (/admin/structure/types/manage/{node type}/display
  128. and select the Display 'Energy level + emit' setting. The field will now
  129. display the current energy value.
  130. - Edit the node and check the Energy value in the field. The value is the same
  131. as the displayed value in the previous hint.
  132. - When a page is visited a POST request should be fired to
  133. /radioactivity/emit (default storage) or
  134. /path/to/radioactivity/endpoints/file/rest.php (local rest storage)
  135. - Emissions re stored in the database table (default storage)
  136. `SELECT * FROM `key_value` WHERE `name` = 'radioactivity_incidents';`
  137. or is in file at /tmp/radioactivity-payload.json (assuming the server
  138. temporary storage is /tmp)
  139. - Cron reports the Radioactivity processing results. Example
  140. ```
  141. drush cron
  142. ...
  143. [notice] Processed 2 radioactivity decays.
  144. [notice] Processed 1 radioactivity incidents.
  145. ```
  146. The numbers refer to the number of entities processed, not the individual
  147. incidents. Unpublished entities also gets counted, but their data is
  148. not processed (no decay).
  149. Set the Granularity to 1 to make sure each cron job will update the energy.