Customising matomo without losing changes on update

Hi guys

I would like to keep a persistent change to the VisitorDetails.php file found in \plugins\Actions.

Is it possible to make that change to Matomo’s core function without losing the changes/customisation when Matomo get’s updated.

Does this have to be done by creating a plugin? Can a plugin extend or modify a public function in VisitorDetails.php?

Thanks

What is the recommended way of making a percipient change to the matomo core?