Hook to get details of taxonomy term page I wrote a module to store taxonomy page details to DB. My requirement is to store tid, term name, vid and UNIX timestamp to DB table on every load of taxonomy term page. Here is my code:

function reporting_api_taxonomy_term_load($terms) {
  $tid = $terms[arg(2)]-&gt;tid;
  $vid = $terms[arg(2)]-&gt;vid;
  $term = taxonomy_term_load($tid);
  $name = $term-&gt;name;
  db_insert('reporting_api')
    -&gt;fields(array(
      'tid' =&gt; $tid,
      'name' =&gt; $name,
      'vid' =&gt; $vid,
      'timestamp' =&gt; REQUEST_TIME,
    ))
    -&gt;execute();
}


But it creates unwanted rows with timestamp only. Can any one help to fix this. Is hook_taxonomy_term_load is the correct hook.
Taxonomy terms can also be loaded when you're not on a taxonomy page, so arg(2) will be empty, hence empty records. 

To fix:

$term = menu_get_object('taxonomy_term', 2);
if ($term) {
  db_insert('reporting_api')
    -&gt;fields(array(
      'tid' =&gt; $term-&gt;tid,
      'name' =&gt; $term-&gt;name,
      'vid' =&gt; $term-&gt;vid,
      'timestamp' =&gt; REQUEST_TIME,
    ))
    -&gt;execute();
}