How to insert Google Analytic Event tracking code in a Guided Marketo Landing Page?

Anonymous
Not applicable

Hello,

I came across in difficulties for inserting ga event tracking code in a marketo landing page. I have 3 different form & I want to track their activity.

I was trying something like below which seems not working.

<!-- EVENT TRACKING Download --> 

<script src="//app-ab06.marketo.com/js/forms2/js/forms2.min.js"></script>
  <form id="mktoForm_2745"></form>

<script>MktoForms2.loadForm("//app-ab06.marketo.com", "290-DNL-975", 2745, function(form) {
    form.onSuccess(function(values, followUpUrl) {
      ga('send', 'event', 'lead', 'trial', 'window.location.href');
      });
  });
  </script>
  <!-- EVENT TRACKING Download-->

May you kindly provide me the steps to do this.

Thanks

Gyan

15 REPLIES 15
SanfordWhiteman
Level 10 - Community Moderator

Gyan Contact​ please link to a live URL. I can tell you straight away that your code is broken because you aren't using the GA hitCallback option: in production, you'll lose huge swaths of data. Nevertheless you be able to gather some data, not none, provided you test using late-model Firefox or Chrome.

Anonymous
Not applicable

Hello,

My landing page is built in with a guided landing page template.

My issue is How & Where to insert Event tracking code ?

SanfordWhiteman
Level 10 - Community Moderator

You can insert it into the template (which in many cases is where you want it, rather than having to add it manually to all derived LPs).

You can use a Text or Rich Text {{my.token}}. You can use a snippet.

What you can't do -- without causing an unnecessary technical burden -- is use a mktoText variable, because these variables are HTML-encoded upon output. This is similar to the default behavior of custom text fields at the Lead level.

Bottom line: in some contexts, "text" really means "text for output," which means HTML encoding is necessary.

Anonymous
Not applicable

Thanks that answered my question. So I can use a Program Token to insert code.

Looking closely at Gyan's question I don't think that's the issue there, I think it probably that has more to do with Google Event Tracking. Sorry for the distraction.

Anonymous
Not applicable

Are you not receiving anything in Google Analytics? Have you tried to debug the process line by line? Are you getting any error messages in the console when you do so?

Anonymous
Not applicable

I also have a similar issue. What I've found by viewing the page source is that Marketo is converting our Google AdWords tracking code into HTML entities. We also have a guided landing page with a footer section that can be changed and code added that doesn't display as part of the page. The solution should be to allow this without converting to entities. What is happening is that the < > are getting converted to &lt; and &rt; so the script type and other declarations are not working properly.

How can we get tracking code to be inserted into a landing page without having these converted to HTML entities? Marketo is trying to help but instead it is just messing things up by converting these for us. I've treid converting these < > characters to entities before adding the code to the guided landing page but of course that doesn't help - we're not trying to display the code, we're trying to get the code itself into the page html.

Here's what's happening in my page source:

&lt;!-- Google Code for Download Conversion Page A --&gt; &lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ var google_conversion_id = 877836615; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "ffffff"; var google_conversion_label = "nJpfCJet82gQx_LKogM"; var google_remarketing_only = false; /* ]]&gt; */ &lt;/script&gt; &lt;script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"&gt; &lt;/script&gt; &lt;noscript&gt; &lt;div style="display:inline;"&gt; &lt;img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/877836615/?label=nJpfCJet82gQx_LKogM&amp;amp;guid=ON&amp;amp;script=0"/&gt; &lt;/div&gt; &lt;/noscript&gt;

SanfordWhiteman
Level 10 - Community Moderator

If you are adding directly to the template, this should not be happening.  Are you using an interstitial {{lead.token}}?

Anonymous
Not applicable

Not sure if this is the same issue Gyan is encountering, don't want to hijack the thread, but I think it is a very similar issue, because of the mention of "Guided Landing Page" rather than "Guided Landing Page Template."

I'm trying not to have to add code directly to the template - what is the point of having templates at all if they cannot be used for multiple landing pages? That's not the definition of a template. We have to create these new pages at the drop of a hat.

Currently in the <head> we have

<meta class="mktoString" id="gConversion" mktoName="Google AdWords Conversion" variable="${gConversion}">

and then in the <footer>

${gConversion}

Should we use mktoSnippet instead?

SanfordWhiteman
Level 10 - Community Moderator

Yes, you should not use mktoText variables for HTML content.

Anonymous
Not applicable

There isn't a mktoText variable; that is an element type/class: Understanding Elements and Variables in Guided Templates - Marketo Docs - Product Docs . You should be able to use HTML code in a mktoString variable it if you set the "allowHtml" attribute to true.

Anonymous
Not applicable

That "allowHtml" is exactly what I was looking for. I knew there must be some kind of easy setting to prevent this behavior.

SanfordWhiteman
Level 10 - Community Moderator

Yes, obviously I meant "mktoString," that was a typo. I forgot about allowHtml, though. Thanks!

At any rate mktoString variables are a highly questionable place to put a whole code block.

Anonymous
Not applicable

What would be a less-questionable place to allow inserting a codeblock?

SanfordWhiteman
Level 10 - Community Moderator

What would be a less-questionable place to allow inserting a codeblock?

I never want template consumers (LP content authors/marketers) to be in control of how page activities are tracked. They might control whether page activities are tracked or not using a mktoBoolean variable, but I see only disasters when freeform code is encouraged at the LP level.

Though it's impossible to technically stop LP authors from adding code that breaks other code (even if just the HEAD accepts HTML, that's enough to break stuff) I don't want to make it an accepted option.  Even if only developers are adding and modifying code blocks (based on the honor system?) how do you efficently fix bugs -- like the bug I noted is in your code now -- when you have the code pasted separately into a bunch of LPs?

Anonymous
Not applicable

Someone of your stature is not allowed to make such mistakes!