Re: We want to get a lead id and pass It to google analytics when a user fills out a form

Anonymous
Not applicable

We want to get a lead id and pass It to google analytics when a user fills out a form

Marketo Analytics – get lead id

We want to get a lead id and pass It to google analytics when a user fills out a form

5 REPLIES 5
Grégoire_Miche2
Level 10

Re: We want to get a lead id and pass It to google analytics when a user fills out a form

Hy Mayank,

You can pass the lead ID to GA as soon as the lead is identified.

It's explained here : Integrating Google Analytics with Marketo

-Greg

Anonymous
Not applicable

Re: We want to get a lead id and pass It to google analytics when a user fills out a form

The blog post doesn't make it very clear how {{lead_id}} is being passed. Do you know if it is possible to simply get the lead id on a successful form submission?

Grégoire_Miche2
Level 10

Re: We want to get a lead id and pass It to google analytics when a user fills out a form

Hi Chris,

Yes it is. Just change the google UA code as described by Courtney:

<script>// <![CDATA[ (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', 'YOUR GOOGLE UA ID HERE', { 'userId': '{{lead.Id}}' }); ga('send', 'pageview'); ga('set', 'dimension1', '{{lead.Id}}'); // ]]></script>

This will register the LeadID as a dimension for filtering in GA

And edit the form code as indicated here: How do you calculate the number of times a form was filled out?  to register events in GA.

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: We want to get a lead id and pass It to google analytics when a user fills out a form

Greg, this won't actually work because the back-end lead association is asynchronous.  You are not guaranteed to have the correct {{Lead.Id}} available on the next page view after submitting a form.  Very soon after, yes, but not instantly.

SanfordWhiteman
Level 10 - Community Moderator

Re: We want to get a lead id and pass It to google analytics when a user fills out a form

Chris (and Mayank) see my response above. What you're looking to do is not straightforward.  The reason is that the process of linking a Munchkin cookie with a lead does not occur before the form submission task is complete.  Rather, it occurs very soon after.*  Usually, it's < 2 seconds after, though with a heavily loaded, large instance it could take longer. But the correct {{Lead.Id}} definitely cannot be expected to be resolved when the form's onSuccess event is finished and the Thank You URL opens, just milliseconds after the form post completes.

It is possible to write some elegant JS to interact with third-party service and get signaled when the token is ready.  But this requires coordination with a webhook, and as long as you're using a webhook I recommend a far easier approach: use a webhook to set the User ID.  The GA Measurement Protocol (which is really just formal documentation of the /collect endpoint) allows you to do whatever you'd do from the client, from the server.  So you'd pass the GA Client ID as a hidden field on the form.  Then, within Marketo itself, set up a webhook that'll log the form post event w/the GA User ID = Marketo Lead ID.

Of course, if you are not familiar with these technologies you'd need to use a developer.

* Some of this behavior may change with the upcoming Munchkin upgrade, but it's too soon to tell.