Q:

Echo wordpress page title into onsubmit

I have a single contact form the runs through the footer of every page on my site.
I have got the page title to echo out using wp_title but it is appearing before the form rather than in the string.
$html .= sprintf( '<form onsubmit="ga(\'send\', \'event\', \'newsletter\', \'submitted\', \'' . wp_title('') . '\')" %s>', $atts ) . "\n";

It appears like this:

A:

From documentation:
Your code
wp_title( string $sep = '&raquo;', bool $display = true, string $seplocation = '' )

secod parameter determines if the title will be echoed or returned, in Your case you should set $display parameter to false.
Solution:
$html .= sprintf( '<form onsubmit="ga(\'send\', \'event\', \'newsletter\', \'submitted\', \'' . wp_title('', false) . '\')" %s>', $atts ) . "\n";

