Add new comment
Node Comment and Forum working together to boost user participation
It is frequent that customers approach us asking for help to rescue their projects from site builders. Sometimes they have technological issues (mainly slow sites) but sometimes it's just plain bad usability os some wrong marketing concepts.
We recently were asked for help from a site that gets about 5,000 unique visitors a day. Despite the not so bad visitor numbers for their niche, this page was getting very low user interaction. They barely got a handful (<10) of comments and forum posts in a whole year timespan.
Among the many changes we did, there was something new a member of our team came up with: linking node comments and forum posts. We noticed in GA that although having very little activity,forums got some attention, but just like it happens in a bar, if no one is dancing you are probably not going to be the first one. On the other hand, users commented on the sites contents and these comments got lost in the > 20,000 content nodes this sites has.
The idea was simple: for each comment thread in a node, there should be a forum post, and they must be syncronized (if someone comments on the forum it should appear on the node and vice versa).
All the magic can be easily implemented through hook_comment_insert:
function mymodule_comment_insert($comment) {
// Crear un comentario de foro!
$node = node_load($comment->nid);
// Need a flag to prevent recursive behaviour.
static $executed = FALSE;
if (!$executed) {
$executed = true;
if ($node->type != 'forum') {
// Buscar un tema de foro con el mismo título.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'forum')
->propertyCondition('status', NODE_PUBLISHED)
->propertyCondition('title', $node->title, '=')
->addMetaData('account', user_load(1)); // Run the query as user 1.
$result = $query->execute();
$forum = NULL;
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$forum = node_load(reset($news_items_nids));
// Añadimos como comentario nuevo.
unset($comment->cid);
$comment->nid = $forum->nid;
comment_submit($comment);
comment_save($comment);
}
else {
$forum = new stdClass(); // Create a new node object
$forum->type = "forum"; // Or page, or whatever content type you like
node_object_prepare($forum); // Set some default values
$forum->title = $node->title;
$forum->language = $node->language; // Or e.g. 'en' if locale is enabled
$forum->uid = $comment->uid; // UID of the author of the node; or use $node->name
$value = "<p>Opinión sobre el artículo: <a href='/node/" . $comment->nid . "'>" .
$node->title .
"</a></p><blockquote>" .
$node->field_entradilla[LANGUAGE_NONE][0]['value'] .
"</blockquote>" .
$comment->comment_body[LANGUAGE_NONE][0]['value'];
$forum->body[$node->language][0]['value'] = $value;
$forum->body[$node->language][0]['summary'] = '';
$forum->body[$node->language][0]['format'] = 'filtered_html';
$forum->taxonomy_forums[$node->language][0]['tid'] = 475;
if($forum = node_submit($forum)) { // Prepare node for saving
node_save($forum);
}
}
}
else {
// Aplicamos a la inversa, el comentario del foro
// lo pasamos al nodo para que las conversaciones
// estén sincronizadas.
// Buscar un tema de foro con el mismo título.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'forum', '<>')
->propertyCondition('status', NODE_PUBLISHED)
->propertyCondition('title', $node->title, '=')
->addMetaData('account', user_load(1)); // Run the query as user 1.
$result = $query->execute();
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$forum = node_load(reset($news_items_nids));
unset($comment->cid);
$comment->nid = $forum->nid;
comment_submit($comment);
comment_save($comment);
}
}
}
}
Along with this change we also made some very basic adjustments such as:
- Allowing anonymous comments and remove the need for registering
- Reducing the number of fields in their subscribe form from 5 to 2.
- Adding subscribe pop-ups
- Etc.
The result? Conversions (newsletter subscriptions in this case) were up from 1-2 per day to 25-50 in less than 2 weeks, and user activity in forums has been growing steadily day after day.
Our customer was sad that he had lost a 1 year (since the site was re-launched using Drupal) in user conversions and engagament, but happy to have now found the right partner to make his project succeed.