Tracking Customer Lifetime Value in Google Analytics

Customer Lifetime Value (LTV or CLV) is the amount of money that a person is predicted to spend with you over their lifetime. It is a calculated metric based on their past behaviour and the behaviour of other people you have seen with similar attributes.

This post is about getting that lifetime value into Google Analytics so you can segment users by it. It is not about the methods of calculating it.

You’ve got the value, now what?

You’ve calculated the lifetime value of all your customers by crunching through your CRM and backend data, and have it in a nice looking CSV file.

Customer ID Lifetime value (£)
001 100
002 150
003 400
004 300
005 50

How do we get this data into Google Analytics?


To make this happen, you will need Universal Analytics. This is the new version of Google Analytics, which is soon to be coming out of beta (as of November 2013).

UA lets lets you associate extra pieces of information to events and/or pageviews with custom dimensions and custom metrics. To get it, simply create a new Property within your Google Analytics Account and select Universal Analytics. Alternatively you can wait until Google release a feature to migrate standard Google Analytics properties to Universal Analytics (again, this is coming in the next few months).

The Methods

There are two methods you can use to get your customer lifetime value into Google Analytics: the Measurement Protocol, or using Dimension Widening.

The Measurement Protocol

The Measurement Protocol lets you send hits to Google Analytics server side. You basically send a request to a URL with all the information as parameters. The main benefit of this is that you can run scripts server side to push data into Google Analytics, without the need for JavaScript tags.

Dimension widening

Dimension widening was released late 2013 and lets you upload a CSV file containing a primary dimension key, and any information associated with that key you want to store in other dimensions.

Which method should I choose?

There are pros and cons to both.

Measurement Protocol Dimension Widening Comments
Person has to return to the site No Yes Dimension widening only occurs once a person triggers a hit on the site via the JavaScript tag. With the MP they don’t have to visit the site for the data to be populated.
Can mix dimension scopes Yes No Widened dimensions need to be the same scope as the key.

For the sake of this tutorial I am going to use Dimension Widening. It is easier to get your head around than the Measurement Protocol and you don’t have to be a programmer to use it. In the real world I would asses the level of experience and needs within the business I was consulting for.

The setup

1. Create an LTV dimension

  • Head to the admin panel within the Google Analytics interface. Select your property, and click on the ‘Custom Definition’ tab.

  • Click ‘Custom Dimension’ and create a new User level custom dimension called ‘LTV’. Save it. I’ll assume this has been created in slot 2 (dimension2). User level scope is used so that the latest value of LTV is always used and overrides any previous values.

Wait, isn’t LTV a metric?

Why are we creating an LTV custom dimension and not a metric? It’s a number so should it be a metric?

Google Analytics sums metrics over time. This means that if I set Bob’s lifetime value to £100 now, then £200 a week later (because he does something to cause his LTV to go up), GA would record his LTV as £300 (£100 + £200) which isn’t what we want.

Dimensions have the concept of scope. They can be set to only remember the last seen value for someone (hence why the LTV custom dimension is set to User level scope).

Why does this matter?

Unfortunately, because we have to set LTV as a dimension in Google Analytics, it makes it difficult to create segments such as:

All users with a LTV < £100

We can only use equals, contains or regex operators because dimensions are treated as strings:

All users with a LTV that equals 100

Bucket your lifetime values

For that reason, I suggest you bucket your users into lifetime value bands or create a simple scoring system such as:

Customer ID Lifetime value (£) LTV bucket LTV score
001 100 50 – 100 2
002 150 101 – 150 3
003 400 350 – 401 8
004 300 250 – 300 6
005 50 0 – 50 1

In this example I will be ingesting the LTV score into Google Analytics during the Dimension Widening process.

2. Create a User ID custom dimension

In order for Google to tie together the LTV we are sending in server side and the session data it is tracking via the JavaScript tags on every page of your website, both sets of data have to have a primary key.

In this case, we are going to use User ID as the key.

This ID needs to be sent to Google during every pageview and event happening on the website (assuming they have identified themselves).

To do this, head to the Custom Dimensions panel within the Google Analytics admin area and add a User scope dimension called User ID. Make a note of the slot it is placed in.

(Please note, this is not the same as Google’s User ID override, a feature they released to help tie people together using different devices, but sadly isn’t out in Europe yet. EDIT – 17th April 2014 – The User ID Override feature is being rolled out at the moment and will be within your account shortly. However, due to it’s limitations (I need another post on that!) I recommend you still set User ID in a custom dimension).

3. Set the User ID custom dimension

The next step is to ensure that the User ID dimension is set for anyone who visits your site and you can identify. I recommend you set the dimension on every page, before the send pageview command:

ga('create', 'UA-XXXXXXX-X', 'insert your domain');
ga('set', 'dimension1', 'insert user ID');
ga('send', 'pageview');

You will need to speak to your dev team to get the user ID field in the above script snippet populated server side. Remember to change the slot number to whatever your user ID slot is.

4. Create the Data Import

By now you should have the following:

  • An user scoped LTV customer dimension in slot 2
  • A user scoped User ID customer dimension in slot 1
  • Updated your Javascript tracking code to set the User ID dimension on all pages

We can now proceed to creating a data import file.

  • Head back to the admin panel within the Google Analytics interface. Select your property, and click on the ‘Data Import’ tab, and then the ‘New Data Import’ button.

Google Analytics Data Import

Google Analytics Data Import

  • Select ‘Generic Dimension Widening’ then click the ‘Next Step’ button.

Generic dimension widening

  • Give your import a name, select the view you want the data to be widened into, and click ‘Next Step’.

Naming your data import

  • Select ‘User ID’ as your primary key and select ‘LTV’ as your Widen-to dimension.

Key set to user ID

  • Tick the radio button that says ‘No – when both widened data and hit data is available, use hit data’. This is done in case you want to override the LTV value in the browser using the traditional dimension Javascript setting code.

  • Click save. You will now see a button that allows you to download the data import schema.

Download data import schema

  • Download the file and open it in Excel or any CSV editor. You will see the first row has been filled in with the values dimension1 and dimension2. Your dimension numbers may differ if you set up your User ID and LTV dimensions in different slots to me.

  • Fill in the rows with user ID and LTV score pairs (remember we are using a lifetime value score rather than the actual value to get around the fact that custom dimension are created as strings in Google Analytics). Save the file as a CSV. An example file would look like this:

CSV file for data import

  • Return to the Google Analytics admin, select ‘Data Import’ and click ‘Manage Uploads’.

  • Click ‘Upload file’ and upload your CSV file. Google will begin processing the data. This can take up to 24 hours.

Congratulations. You have now added lifetime value to Google Analytics!

(For the more technical amongst you, have a look at Custom Data Sources in the Google Analytics Management API. Rather than having to manually upload your CSV file you can use this to automate the process at an interval of your choosing).

What happens now

When a user returns to the site and their hit data is sent to Google’s servers, Google Analytics will perform a look up to see if any of the dimensions being sent need widening. If the User ID dimension is sent with the hit, it will know to also set the appropriate lifetime value score.


The final step is to build some reports or do some analysis using the lifetime value dimension.

Building a custom report

An example report might show how the different LTV groups use the site differently. To build this, create a custom report using the following setup.

Lifetime value report in Google Analytics

This would produce a report such as this (obviously a real one would have more rows – this is dummy data):

Lifetime value report in Google Analytics

Building advanced segments

The second thing you could do is build a segment to just show activity for a group of people with a particular lifetime value score.

Customer lifetime value segment in Google Analyitcs

The advantage of doing this is that you can look through the standard reports and compare two different LTV groups. You can also push this advanced segment to a remarketing list and use it to advertise to specific people on the Google Display Network on in Adwords. DoubleClick remarketing is also possible.

If someone’s lifetime value changed, they would instantly be shown a different set of banners or ads without you having to lift a finger!


So there it is. A way to get customer lifetime value into Google Analytics in order to see how different segments act on your website, or to remarket to them with display advertising.


Need expert Google Analytics help? It may be worth investing in a Google Analytics Consultant.

Ed Brocklebank is the founder of Metric Mogul, an analytics and data-driven email marketing consultancy. He helps business of all sizes use to convert more visits into leads, and nurture those leads into customers and brand advocates.
  • Yair Weil

    Excellent post, thanks for taking the time to write it!

    Would love to hear of more use case examples for it as possibilities are endless.

  • iniesta

    Thanks for sharing this article, this is exactly what I am trying to achieve at the moment. One issue, what value do I need to set as the user ID in the analytic code?

    • Metric Mogul

      You should set it to what ever identifier you use in your backend system (e.g. a CMS, a loyalty card number, etc). That way you can tie actions of a single user across multiple data sets and systems.

  • Pingback: Everything You Need to Know About Customer Lifetime Value