Custom Variables in SPA

I configured 3 custom variables in Matomo.
I want to track these custom variables whenever the value stored in them changes. But there’s a problem, Matomo tracks and displays only the last stored value. Even custom dimensions displays the last stored value.
How should I use custom variable so that it displays & tracks all the values and not just the last stored value.

As you mentioned Custom variables and Custom dimensions, they don’t work similarly.
With Custom variables you can track a list of values, whereas with Custom dimensions you can’t.
How do you track (JavaScript API, HTTP API, MTM)?