I want to add some ecommerce stuff to the javascript tracker but as i can see there is no way to modify the generated piwik script of your module?

If this is correct - this could be changed into a feature request. I guess it could be useful to have a hook_alter() before "add tracker code to scope".

Comments

hass’s picture

Status: Active » Fixed

Look into ubercart module. It has an integration with google analytics. You should be able to use the same way in piwik.

You can help on #231451: Add hook to alter data before sending it to browser.

marcusx’s picture

I once needed to trac a special button click to an external page as a goal and ended up with this quick solution.

/**
 * Implements hook_init().
 *
 * Add javascript that triggers a piwik goal manually.
 */
function MY_MODULE_init() {
  //@todo: can we do this as js attachment to the token?

  $node = menu_get_object();
  if (isset($node) && $node->nid == 329) {
    drupal_add_js('jQuery(".item_action a.button").bind("click", function() {
        tracker = Piwik.getAsyncTracker();
        tracker.trackGoal(1);
        //As we track an outlink we need a real pause before the site is left
        //so there is enough time to record the tracking.
        pause(500);

        function pause(millis) {
          var date = new Date();
          var curDate = null;
          do { curDate = new Date(); }
          while(curDate-date < millis)
        }

      });',
      array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
    );
  }
}
checker’s picture

I have an easy solution for my problem to add an ecommerce order. Just add the javascript code inline with a higher weight than piwik javascript.

It should look like this:

<script type="text/javascript">
<!--//--><![CDATA[//><!--
var _paq = _paq || [];(function(){var u=(("https:" == document.location.protocol) ? "test" : "test");_paq.push(["setSiteId", "3"]);_paq.push(["setTrackerUrl", u+"piwik.php"]);_paq.push(["trackPageView"]);_paq.push(["enableLinkTracking"]);var d=document,g=d.createElement("script"),s=d.getElementsByTagName("script")[0];g.type="text/javascript";g.defer=true;g.async=true;g.src="test";s.parentNode.insertBefore(g,s);})();
//--><!]]>
</script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
var _paq = _paq || [];_paq.push(["addEcommerceItem","12931","Test","No category",399,1.00]);_paq.push(["trackEcommerceOrder","310",402.9,399,64.33,3.9,false]);
//--><!]]>
</script>

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.