Title: Feature Request: Adding custom variables
Last modified: August 21, 2016

---

# Feature Request: Adding custom variables

 *  [Mooash](https://wordpress.org/support/users/mooash/)
 * (@mooash)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/feature-request-adding-custom-variables/)
 * I add the following code below to my Piwik tracking code manually in header.php
 *     ```
       <?php
               $category = get_the_category();
               if (!is_front_page() && !empty($category[1])) {
                   echo '  _paq.push(["setCustomVariable", 1, "Category", "'.$category[1]->cat_name.'", "page"]);
               ';
                   echo '  _paq.push(["setCustomVariable", 2, "Sub-Category", "'.$category[0]->cat_name.'", "page"]);
               ';}
               elseif (!is_front_page() && !empty($category[0])) {
                   echo '  _paq.push(["setCustomVariable", 1, "Category", "'.$category[0]->cat_name.'", "page"]);
               ';}
               if (is_404()) {
                       echo '_paq.push([\'setDocumentTitle\', \'404/URL = \'+String(document.location.pathname+document.location.search).replace(/\//g,"%2f") + \'/From = \' + String(document.referrer).replace(/\//g,"%2f")]);';
               }
               ?>
       ```
   
 * Basically if I’m on a post it adds the Category as CustomVariable 1 and adds 
   a sub category as customvariable 2 if it exists. It also tracks 404’s (Which 
   wp-piwik can already do)
 * What I’d like to see is this other functionality built into wp-piwik if possible,
   so I can track my custom variables.
 * Sorry if I’m posting in the wrong section!
 * [http://wordpress.org/plugins/wp-piwik/](http://wordpress.org/plugins/wp-piwik/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [braekling](https://wordpress.org/support/users/braekling/)
 * (@braekling)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/feature-request-adding-custom-variables/#post-4393284)
 * You can currently set custom vars per posting. Does this help? (Of course it 
   would be nice to add different information automatically, but maybe it will work
   for you to add it manually until the feature is implemented.)

Viewing 1 replies (of 1 total)

The topic ‘Feature Request: Adding custom variables’ is closed to new replies.

 * ![](https://ps.w.org/wp-piwik/assets/icon-256x256.png?rev=3529668)
 * [Connect Matomo - Analytics Dashboard for WordPress](https://wordpress.org/plugins/wp-piwik/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-piwik/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-piwik/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-piwik/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-piwik/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-piwik/reviews/)

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [piwik](https://wordpress.org/support/topic-tag/piwik/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 1 reply
 * 2 participants
 * Last reply from: [braekling](https://wordpress.org/support/users/braekling/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/feature-request-adding-custom-variables/#post-4393284)
 * Status: not resolved