I have Google Analytics set up on my site and its displaying the Client Id of my visitors ok on the User Explorer Report.
I want to send the Google Analytics Client Id in a hidden field in my contact form (so I can compare users who send a form with their behaviour on my site as shown in GA).
I have used the script from the GA guide (https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id) at the top of my body code :
<script>
$( document ).ready(function() {
ga(function(tracker) {
var clientId = tracker.get('clientId');
});
});
</script>
I hoped this would collect the client id and put it into clientId
I added
<?php echo"clientId" ?>
to the page to check.
However, when I visit the page (https://www.cow-shed.com/cow-shed-business-start-up-pages/contact.php) it is displaying clientId rather than a number.
I have a php form which has a hidden field for clientId but this is sending clientId (not surprising probably as the echo code is also showing clientId).
This must be such a useful thing to do, but I can't see how to get the client id into my form. If anyone has any ideas. Please can you keep it simple as I'm an html coder so my pho and js is v basic ...Thank you!