Success!
Here is the code as it stands:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//
www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-YY', '
domain.com');
ga('send', 'pageview');
var clientId = "";
ga(function(tracker) {
clientId = tracker.get('clientId');
ga('send', 'pageview', {
'dimension1': clientId
});
$('#clientid').val(clientId);
});
</script>
Obviously UA-XXXXXXX-YY and
domain.com need to be customised, as does 'dimension1' but with the basic jQuery library on the page we were also able to pass back the clientId to a hidden form field - that's what the "$('#clientid').val(clientId);" part is doing - the form field name is specified after the hash/pound (#) symbol.
Thanks again for everyone's help!