could we use this technique especially to set the email address and therefore to promote a lead to become known ?
It won't work for lead promotion. In that case you would use either Munchkin API associateLead or Forms API hidden submit. I really prefer Munchkin associateLead, but you can't do that purely client side. I'm writing up a blog post on how to track non-Marketo email clicks (for which I almost exclusively use associateLead, but since those are emails you are able to securely precompute the Munchkin "associator token").
I recently had to solve this exact issue at Yesware and wrote an open source library which will do it for you.
Firstly, it's important to understand how UTM parameters work when using Google Analytics. UTM parameters apply to a single visit (session) only. If a user clicks on a link which is tagged, that session will be associated with the UTM parameters. E.g. ?utm_source=adroll&utm_medium=display will place that session into the Display channel within Google Analytics. If the user fills out a form during that session, you'll want to define that as a goal with in GA and you'll be able to see the conversion rate of that channel. If the user doesn't convert and then comes back to your site, you won't want to reuse any previous UTM parameters as they won't be correct.
The previous version of the GA tracking code would save these for you in a cookie named _utmz, but the current version no longer does this.
When a user visits your site with UTM parameters in the URL, you'll want to save these into a cookie which expires at the same time as the GA session, which by default is after 30 minutes of inactivity. If at any time in the session new UTM parameters on the URL are detected, then the previous values should be overwritten as GA has started a new session at this point.
When a user fills out a form (becomes known), you'll want to fire a GA event which is setup as a Goal in GA and also pass the saved cookie values to Marketo.
I've created a library to do the first piece: https://github.com/Yesware/last-campaign
On every page of your site, you would just include the script and call "lastCampaign()", this will save the UTM parameters into a session cookie.
Then on your form you can add hidden fields with populated with the value of the cookies: utm_campaign, utm_medium, utm_source, utm_term, and utm_content. Alternatively, you can use some JavaScript on your landing pages which will automatically add the hidden fields and populate them. Here is an example that will do that for you: https://gist.github.com/lukebussey/c1aeb4113e90c519d522
I hope this is helpful.
Here is an example that will do that for you: https://gist.github.com/lukebussey/c1aeb4113e90c519d522
Cool script! But it has a race condition that a 200ms timeout will not fix. Use the hitCallback as noted here: https://nation.marketo.com/thread/5577#118658. This kind of thing is frequent source of lost logs.
Fantastic. Thanks!