Search code examples
matomo

Set a dimension and goal with piwik


I think what I want is so simple but I can't figure it out.

I have a form that visitors can fill out on the site. I want to do two things with this form:

  1. Get the user's name from the form and set it as a custom dimension value (which I'll do with a js variable)
  2. Upon form submission, track it as a completed goal

I know how to set a goal and I know how to set a dimension but how can I do both on the same submission? I tried chaining them like this:

<input type="submit" onclick="javascript:_paq.push(['trackGoal', 1]);  _paq.push(['setCustomDimension', customDimensionId = 1, customDimensionValue = 'TestValue']);">Submit</button>

But that doesn't work.

If I take the custom dimension off, I can trigger the goal. However, I can't seem to set the custom dimension value from the button. I can set it if I put _paq.push(['setCustomDimension', customDimensionId = 1, customDimensionValue = 'TestValue']); in the footer - but that's it.

I've also read this: http://developer.piwik.org/guides/tracking-javascript-guide#custom-dimensions but none of those examples work for me.

What am I missing?


Solution

  • Per the piwik crew: the proper way to track a goal and a dimension is this:

    _paq.push(['trackGoal', idGoal, customRevenue, {dimension1: 'DimensionValue'}]);
    

    I was having trouble at the time because the docs were not up to date. They seem to be now.

    https://developer.piwik.org/guides/tracking-javascript-guide#tracking-a-custom-dimension-across-tracking-requests