Tracking Goals Programmatically

I want to track dynamic pages as goals so I can see which content is being viewed… so I have added the code:
‘’

to my pages… however looks like I have to actually add each apikey into Goals on the piwik server… is there anyway to get around that and just have the goal created if it is not already when I make the trackGoal call?

You should maybe use: Custom Variables Analytics - Analytics Platform - Matomo instead of Goals ?