If you use Marketo Forms 2.0 then this documentation is critical for understanding how to track form submissions. This example specifically serves two important functions: first, it shows how to handle an onSubmit action, and second it shows how to grab the values from a form. Here’s the code from the example:

This code can be repurposed to “listen” for a Marketo form submission. To track this via Google Tag Manager, start by creating a custom HTML tag: select tags

Click the “New” button and select Custom HTML:


If you are generating leads through a content strategy (KissMetrics generates a crazy amount of leads just through their blog) and you are using a Marketo form for lead generation then the code for the custom HTML tag might look something like this:

The next step is important: you need a trigger for this custom HTML tag to fire, ideally a trigger that will load the custom HTML when a page with a Marketo form loads. For example, if you have gated content (such as white papers) you’ll need to use a trigger that covers all those gated pages. It’s not a good idea to trigger this tag on every page, so try to trigger this script only when the Marketo form is actually present.

Now that you have a tag and a trigger to fire the custom HTML on page load, let’s walk through each line to better understand what’s going on:

For each of the new dataLayer variables you use (such as “marketoCompany” and “marketoLeadSource”), you’ll need to add those in the Variables section of Tag Manager:

And select Data Layer Variable:
datalayer var

Now fill out the details for the variable:
make variable

Progress check: we have a new “listener” for forms that’s only triggered on pages where a forms exists. We have variables from the dataLayer. Next we’ll need a trigger and one more tag. The trigger listens for marketoFormSubmit event we created in the first tag:

Almost there…one last tag to setup!

The last thing we’ll need is to send this to the relevant tracking service. Since this is Tag Manager, we could send this to multiple services; the example below is for Google Analytics.

Go to Tags, select “New” and create a Google Analytics event tag (hopefully you are using Universal Analytics by now!). Select the “Event” track type and fill in the values as needed:
final tag

Of course, add the new trigger we just created. Test this out in Preview mode, and if everything works as expected, hit Publish.

Et voilà! You can track Marketo forms to your hearts content.


Read more

There are many situations where you might like to get data from a database and into a pandas data frame. The simplest way to is to initialize a dataframe via the pandas read_sql_query method. The ORM of choice for pandas is SQLAlchemy. By installing a few more packages, you can query Redshift data and read that into a dataframe with just a few lines of of Python code.

The Setup

This post assumes you have a number of Python packages already installed, such as pandas, numpy, sqlalchemy and iPython. I’ve used the Python distribution Anacoda, which can be downloaded here. It comes packed full of all the libraries you might need for data analysis.

The Dialects documentation for SQLAlchemy mentions that Redshift is supported through another Python package; this package also depends on a Postgresql driver. So, the additional packages needed for connecting to Redshift are redshift-sqlalchemy and psycopg2. If you already have Anaconda, you can install psycopg2 quickly using conda. For getting redshift-sqlalchemy installed, here are some docs on using conda/pip in conjunction with each other. TBH I just used downloaded the package and did this in my terminal:

Of course, I did this in my default environment. Everything seems to work, but the Anaconda docs are very useful if you have multiple Python environments on your machine.

On To The Data

Start iPython in your terminal (or Notebook if you prefer). Note that the connection string follows the pattern ‘flavor+DBAPI://username:password@host:port/database’. Make sure to change the connection string below to your own!

If we look at the “test” object we see:

Read more

Honestly, the hardest part is authenticating. I’m assuming you’ve already created a project in Google’s Developer Console, turned on the GA API, setup a client_secret credential, and requested access to the real-time API beta:

  1. Copy and paste the URL that is printed from authorize_url
  2. Click “Accept” when prompted; you will be redirected to a page with a long URL
  3. Paste line 25 into your console
  4. Now, input that long URL
  5. Boom, you should be on your way

Make sure to change the hard-coded paths in here to wherever you store you Google Analytics account information and the client secrets you got from the developer console.

A few to-do items:

  • This is a really manual process for getting auth tokens…obviously there is a better way
  • I’d much rather use Python’s requests library
  • Need to parse the blob of JSON that is returned

Here are some pages I found helpful:

Read more