Returning HTML after tracking

I am currently trying to integrate the piwik tracker with a “custom popup” serving service, and for the moment I am “hacking” the tracker php and js code to work this wat.

I made a custom plugin where we save the “rules” (url, time on site, visit number) and some custom html from within the Piwik dashboard. It also hooks to the tracker php file and whenever there is a new page view it compares the visitor/action info to determine if the custom html should be returned. If that is the case, it returns the custom html save, and the modified piwik.js displays whatever is returned on the client site.

Now, as it is, it works, but I can’t get past the “hackyness” of this solution, and I am not sure if there is a better way to handle this. Plus, this has prevented me from updating Piwik, as the files that had the custom hooks get rewritten and all that work is lost.

Is there a better way I could accomplish this?