Managing Google Analytics Goals in Drupal

intel goals tutorial header

Managing Google Analytics Goals in Drupal

 A vital step towards more meaningful analytics is the proper use of goals. One of the challenges of Google Analytics is having to keep its goals in sync with changes in your Drupal site. The Intelligence module provides a much more flexible and integrated way of managing your Google Analytics goals from within Drupal’s admin.

The goal of this tutorial will be to walk through how to setup IntelligenceTM, our Google Analytics with Drupal module to enable you to trigger your analytics goals and assign custom values on any Drupal entity. Before starting this tutorial make sure you have the latest version of the Intelligence module installed.

Setting up goals in Google Analytics

Before you can configure LevelTen Intelligence to manage your goals you must setup corresponding Google Analytics goals. Once the goals have been setup the first time, you will be able to customize them within Drupal without having to make additional changes in Google Analytics.

To do the initial goal setup go to the Google Analytics Admin for the property you are using with LevelTen Intelligence. If you are in the right place you should see three columns labeled Account, Property and View (Profile).

Google Analytics adding view goals

Under the View (Profile) column click Goals. On the goal list page, click the Create a Goal button.

Google Analytics Goal setup templates page

With newer Google Analytics accounts the first step will be a Goal setup page that gives you several Templates to choose from. If you see this page, select the Custom radio button and then click Next step. If you don't see this page simply proceed to the next step described below.

Google Analytics adding a event triggered goal

Under Goal description, create a name for your goal. For the Type, select Event then click Next step.

Google Analytics using regular expression event goals

Under Goal details, set the drop down box next to Category to Regular expression. The input for the text field should follow the pattern:
[Goal name]\+$

If for example you were setting up a goal for when someone submits your contact form you would enter:

Under Use the Event value as the Goal Value for the conversion, make sure the slider box is set to Yes.

Finally click Save Goal.

Repeat these steps to setup additional goals as needed.

Setting up goals in Drupal

Once you have setup your goals in Google Analytics, you need to let Drupal know what they are so they can be triggered properly by the site.

To setup your goals within Drupal go to Admin > Config > Services > LevelTen Intelligence > Scoring. Expand the Advanced settings fieldset towards the bottom of the form.

Adding goals to Intel scoring admin

There are two text boxes to enter your goals; (event driven) Goals and Submission goals. Event goals can be triggered on any page view. Submission goals are a special subset of goals that use special logic to only trigger when a form is submitted. Submission goals will be covered in a latter post about conversion tracking. For now it is fine to add all your goals to the standard event driven goals text box.

Enter one goal per line as | (pipe) separated elements. The first element should be the Goal ID set by Google Analytics. The Goal ID can be found in the goals list in Google Analytics. The second element is the goal name (title). The third is an optional description to use for administrative purposes.

Finding Google Analytics goal ids

Triggering goals with fields

Now that Drupal knows how to sync with your Google Analytics goals, we can trigger them from nodes and other entities. The Intelligence module uses the fields system to attach goals to nodes.

Node level goal settings uses a pair of fields; one to select which goal to trigger and another to assign the value for that goal. Since the two fields are coupled together and multiple goals can be triggered per page, field collections are used to help organize the user interface.

Field collections are provided by the Field collection module. Download and install this module if it is not already installed on your site.

One field collections are enabled go to a content type you want to add selectable attributes by going to Admin > Structure > Content types > [content type] > manage fields.

Adding intel event col field to basic page

On the manage fields page, add a field with the following values:

  • Label: Events
  • Machine name: field_intel_event_col
  • Type of data: Field collection
  • Form element: Embedded

Click Save at the bottom of the page. On the next page, Field settings, leave the defaults and click Save field settings. On the form field form change the number of values under field settings to Unlimited. Click Save settings.

Intel events col field settings

Now that we have the collection created, we need to add the actual fields to the collection. Do this by going to Admin > Structure > Field collections >  and for the field_intel_event_col field click on manage fields under Operations.

Field collections list page

On the Manage fields page, add a field for selecting goals using the following settings:

  • Label: Event
  • Machine name: field_intel_event
  • Type of data: List (text)
  • Form element: Select list

Click Save.

Intel event goal selection field

On the next page, Field settings, you don't need to change anything so simply click Save field settings. The next page presents the full instance field settings. You don't need to change anything on this page either, so simply click Save settings. Note, you want to leave the Number of values setting at 1.

Once done creating the select field you should be back at the Manage fields list for the field collection. Now we want to add a field to set the value for our goals. Add another field using the following settings values:

  • Label: Value
  • Machine name: field_ intel_event _value
  • Type of data: text
  • Form element: Text field

Click Save to create the field.

Intel event goal value field

On the next two fields settings pages the default settings will work fine so simply click the Save field settings button. When the field collection setup is complete you should see the two fields in the list on the Manage fields page.

Completed intel event field collection


Testing your setup

Now your selection fields are setup, you can go back to the content type you originally added the field collection to and you should see the intel event field collection.

Intel events node fieldset

Simply select one of the goals and optionally enter a value. Save the node then view the page.

If everything is setup properly, you should be able to see the goal triggered in Google Analytics in the Real-Time Conversions report.

Google Analytics real time conversion report

Related Posts

Track Contact Form 7 with Google Analytics Goals the Easy Way

Tom McCracken
Read more

Creating Custom Google Analytics Events In Drupal

Tom McCracken
Read more

The Best Gravity Forms Google Analytics Tracking How To?

Tom McCracken
Read more

Video: Valuate Content Using Google Analytics and Drupal

Kylon Gustin
Read more

Google Analytics and Google Spreadsheets: Create Your Own Dashboard

Felipa Villegas
Read more

Five Essential Features of Google Analytics

Read more