AdWords Conversion Tracking via Google Analytics goals

People usually use AdWords Conversion Tracking code that they place on the specific page they would like to measure. For example to measure successfully registration they will place AdWords Conversion Tracking code on the “Thank You for registration” page (some time ago it was the only way to receive AdWords conversions data). That’s quite good solution but sometimes it just isn’t enough… What about single page application? What about some extra metrics that can help to optimize your campaigns?

Note: In this example i’m using Universal Google Analytics API. More information can be found here and here.

Google Analytics goals

If you dont’t know yet what Google Analytics Goals are and why they are so important for you website – this is a must-watch video (great overview on why and how to use GA goals):

Events as Goals: Remember to setup proper events for your Google Analytics Goals so that our registered events can become goals and can be later used for conversion tracking in Google Analytics and Google Adwords.

AdWords conversion tracking with Google Analytics events

Goals collected in Google Analytics can be easily imported to Google Adwords panel. But to do that we need to set up both: Google Analytics and Google Adwords accounts first (if you haven’t done it yet):

After setup, you will be able to import Google Analytics Goals (if any are available) into Google Adwords Conversions panel. Go to AdWords -> Tools -> Conversions and click Import from Google Analytics button (you can also choose which goals to import):

Imported goals will be listed below with proper data.

Notice: If you want to track new events in Google Adwords, you will need to create proper goal in Google Analytics first.

How to track custom events via Google Analytics

Having configured Google Analytics and Google AdWords, we can now start tracking (collecting) our events. Tracking events is as simple as executing proper JavaScript code for given action, e.g. clicking some button, displaying “Thank you for registraion” page or performing certain tasks on page.

Register event via Google Analytics

JavaScript

1

2

3

4

5

6

7

ga('send',{

'hitType':'event',

'eventCategory':'Event Category',

'eventAction':'Event Action',

'eventLabel':'Event label',

'eventValue':'Event value'

});

Important: To be able to use ga object it needs to be initialized first as below:

This code should be executed just after proper action (event) takes place. Let’s imagine a scenario where we want to register simple “Customer Registration” event just after completed registration without refreshing page and without extra “Thank you for registration” page. With jQuery code should look like this:

'Customer Registration

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$.post("/registration-handler-url",function(){

// success

ga('send',{

'hitType':'event',

'eventCategory':'Customer',

'eventAction':'Registration',

// label if needed

'eventLabel':'Popup',

// value if needed

'eventValue':0.99

});

})

.done(function(){

// some other success handling

})

.fail(function(){

// some error handling

});

Server-side tracking API: Measurement Protocol

Events can also be registered on the server side using official server-side tracking API: Measurement Protocol, which allows developers to make HTTP requests to send raw user interaction data directly to Google Analytics servers. This is the missing GA component that allows us to send different types of request:

To register custom event from server side with simple PHP class it’s just a few lines of code:

Register event via Google Analytics

PHP

1

2

3

4

5

6

7

8

<?php

GA::event(array(

'tid'=>"UA-XXXXXXXX-X,

'ec'=>'Event Category',

'ea'=>'Event Action',

'el'=>'Event label',

'ev'=>'Event value'

));

Important: In this example i’ve used very simple PHP implementation of GA class (there are also many different well documented and tested PHP libraries in Github for Measurement Protocol Client).

Registering events on the server side is really useful for example when we want to register / track some transactions which are processed by CRON scripts or any other action that cannot be executed in the browser. In this way we can also register some Google Analytics ecommerce transactions or social interactions.

I’m successfully tracking goals from the server-side API, however, it does not seem to sync up with the client-side tracking. For example, there are no goal funnels, source, data, etc. I was wondering if there was a way to sync server-side tracking with client-side tracking, to get the best of both worlds…