How to end a track and start a new one ?X(

i want to stop a track manully and start a new one ,how can i do ?

my idea is :

var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);

var uid="$_G['uid']";
var uname="$_G['username']";

//when enter the website for the first time
else if(Piwik.getCookie('ck_uid)!=uid))  //when login or logout
	//end the former track
	//start a new track
	var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);

	piwikTracker.setCustomVariable(1, "uid", uid,'visit');
	piwikTracker.setCustomVariable(2, "username", uname,'visit');

Did you find a solution?

I’m looking for the same thing: 301 Moved Permanently

I have the same problem pls somebody help

There is a feature request ticket about being able to set the visitorId in the JS API which would solve this problem: Accurate User Detection cross devices: User ID (set in JS and all other clients) · Issue #3490 · matomo-org/matomo · GitHub