Saving data to Pavlovia for experiments without JsPsych or PsychoJS

URL of experiment:

Description of the problem:
My experiment is written without JsPsych or PsychoJS, but Pavlovia only has instructions of data saving for experiments using those libraries. How can I save data (csv/json files) on Pavlovia for experiments written in vanilla JS? I don’t really want to modify the experiment code significantly to incorporate JsPsych or PsychoJS. Currently I can generate json files and save them locally when I pilot the experiment, but not sure how to save it on Pavlovia. Any suggestion would be helpful, thanks!

This isn’t my area of expertise, but here is a recent thread where similar questions are being asked.

Thanks for the reply!
I followed the suggestion from From JATOS to Pavlovia with jsPsych? · Discussion #2458 · jspsych/jsPsych · GitHub
I use jsPsych call-function to save the data in the index.html as suggested:

var resultsTrial = {
  type: 'call-function',
  func: function() { return data; }
};

jsPsych.init({
  timeline: [resultsTrial, (pavlovia plugins go here) ]
})

However, I have another issue: the experiment just ends and an empty data file is saved. Is it because jsPsych starts before everything? The strange thing is if I use console.log in the main js file, things can be printed but the experiment just ends (elements are displayed normally though).
Below is a screenshot of what I see when I pilot the experiment - Pavlovia’s experiment ending message is displayed before the experiment starts (i can still click through the experiment though…):

Here is what I have in the html script section:

     $(document).ready(function(){
	enter_credentials(start_game)
	user_credentials = participantCode;
	initialize_task(2); //change trial number here
	start_experiment();
        initializeJspsych()

});
        initializeJspsych = function(){
	var timeline = [];
	var resultsTrial = {
  		type: 'call-function',
  		func: function() { return data_log; }
		};
		console.log(resultsTrial)
	timeline.push(resultsTrial)
	/* init connection with pavlovia.org */
	var pavlovia_init = {
		type: "pavlovia",
		command: "init"
	};
	timeline.push(pavlovia_init);

	/* finish connection with pavlovia.org */
	var pavlovia_finish = {
		type: "pavlovia",
		command: "finish"
		};
	timeline.push(pavlovia_finish);
	console.log("#jspsych init");
	return jsPsych.init({
		display_element: 'jspsych-target',
  		timeline: timeline
		})

 }

Is there anything wrong with what I’m doing? Any suggestion would be helpful. Thanks in advance!