Creating rule-based worlflows based on piwik data

I’m attempting to build what is basically a mini or zapier clone within my app. This is where you set workflows that are triggered by events the user selects.

Here’s an example image of what a workflow could look like:

an example workflow could be: When an identified user visits the page with the id of 2, send them an email containing x.

Obviously a good source of the triggers could come from javascript events set on the DOM. This got me thinking: piwik tracks all these by events as well. Maybe I could use Piwik for this and also get access to all it’s events.

I figure there’s two obvious ways to make the initial triggers that the user picks work:

  1. create the url query based on the rules set by the user. So in the example above, the query would be something like site id, user id, page id - the code would just wrap this in an api request to piwik. The problem with this is, I’d have to set up some kind of watcher that constantly pings the endpoint looking for changes. That doesn’t seem very efficient.

  2. figure out if there’s a way to customize the piwik event tracker, or create a custom one, to also alert the predefined workflow triggers that are possible in the app. This way they’re triggered every time something actually happens vs watching for changes.

My questions are:

  1. Is this possible?
  2. am I thinking about this the right way?
  3. are these two options the only ones available to me or are there better ways?

Any help is greatly appreciated.