Custom goal tracking on user event

I have been trying to track a custom goal when a user clicks on a submit button using a javascript function however I cannot seem to get this to work. I am new to Piwik but have been using omniture for a long time and I think i am lost in the differences.

Basically when a user clicks a button I want to log a conversion to goal 1.

function testgoal()
{
piwikTracker.trackGoal(1);
}

This isn’t working because I assume I need to define “piwikTracker” for this function (i am already including the standard javascript code). However whenever I go to define it for this function it never seems to track anything.

I am able to track a conversion to goal one in the standard page view code however that doesn’t let me dynamically log a conversion when a user clicks on a button.

If anyone could point me to code examples or help with this that would be great. The Piwik documentation is not very helpful on this all it have for manually triggering is this “piwikTracker.trackGoal();” which doesnt do anything because it doesn’t really put it in context if I need to call it from a onclick or something like that.

If you want to use piwikTracker during page load, you would have to put the JS code BEFORE you want to use it, instead of the footer. Maybe after the for example?