Form submission


#1

First of all: I used the search and have read some posts, but they didn’t helped me.

What i want to do is:

There for I created a goal and track it like this:

$(‘form[action="/php/do/download.php"]’).submit(function(){
window.setTimeout(function(){
piwikTracker.trackGoal(2, $(this).serialize().replace(/effects%5B%5D=/gi, ‘’).replace(/&/gi, ', '));
}, 500);
});

The goal is tracked correctly, but the second argument which is a comma serparated list of the checked checkboxes isn’t.

Do you have any ideas, how could track this properly?


(Matthieu Aubry) #2

The second parameter to trackGoal() is the Revenue, an integer or float number for money revenue (or equivalent) see Track Goals and Measure Conversions - Analytics Platform - Matomo

However, with Piwik you can track custom variables for Goals. Use a “Visit” session custom variables (eg. name = “Checkboxes” and value = comma-separated-checkbox-names

See Custom Variables Analytics - Analytics Platform - Matomo

Call the setCustomVariable(…) just before trackGoal and it will work oK and display reports in Visitors > Custom Variables, or even just in the Goal > goal X > Custom variables

enjoy!


#3

Thank you :slight_smile:
This solution works great for me.

Here is the final code:


$('form[action="/php/do/download.php"]').submit(function(){
	var $this = $(this);
	window.setTimeout(function(){
		var value = $this.serialize().replace(/effects%5B%5D\=/gi, '').replace(/&/gi, ', ');
		piwikTracker.setCustomVariable(1, 'effects', value, 'visit');
		piwikTracker.trackGoal(2);
	}, 500);
});