Skip to content

Conversion rate per page in Google Analytics with R

(Last Updated On: January 11, 2019)

I often get questions about how to evaluate if a page has been useful in the customer journey on the website. You could check this by a lot of different KPIs but many of them aren’t very good. For example, I think page value is an irrelevant metric since Google analytics will split the transaction value on all visited pages during the session. So if a user likes to browse on multiple pages and all of them are somewhat relevant for that user then the page value for our specific page we want to follow up will be getting low credit, when in reality it was a great page for the user. 

One metric that I like to look at is the conversion rate for that page when it has been visited during the session. This is calculated as the number of visitors who bought something and visited the page during the session divided by the unique pageviews for that same page.

Previously I’ve used segments in Google Analytics to compare the unique pageviews between all users and sessions with transactions. This is however a very slow process, especially if you have a lot of pages you want to analyze. 

So how can we do this in a better way and scale the solution? By using R we can easily do this fast and effective!

First off we import the Google Analytics library and specify which view we are going to import data from. You can do this either by selecting by name or by simply typing the view id. We also create cariables for the time period we want to collect data from. 

In the next part of the script we create our function that is going to extract data from Google Analytics based upon the chosen time period, dimensions, metrics, filters and segments. Notice that you can leave both filters and segments blank if you want to. The script will then return data with a filter which matches REGEX “.*” and use the standard segment “All Users”.

The last part of the script is a function to compare unique pageviews for all visitors with those of the customers. The function uses a variable called ‘pages’. Leave it empty to export data for all pages or type in a vector of pages that you want the data from. Pretty simple right? You can now start comparing your different pages from the perspective of how many of all visitors who viewed the page also decided to buy something. 

 

To run it simply call the function!

If you want the script in full version you can find it on GitHub. I also wrote a query for Google BigQuery if you would prefer to do your analysis there. I apologize in advance if the query is too complicated, I’m not an expert in writing SQL… yet. 

Share this article
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Published inAnalyticsR

Leave a Reply

avatar
  Subscribe  
Notify of
© Copyright 2017-2019 - Linus Larsson