LTV — lifetime value. How to understand during what period of…
By: Andy Guliev
Tags: Data Studio Bi, Bigquery, Bigquery Sql, Google Data Studio

Let’s analyze each of the request blocks in detail.

(1) First piece of code

As a result of executing the first part of the code, we get a table with data for each unique user: the date of the first opening of the application and the amount of sessions within a single day.

In total, we have data when the user first opened the application, how often he used it, and the number of sessions by day.

Code to get this data:

-- ( 1 ) First piece of code - The number of sessions of a unique

-- user on a specific day SELECT user_pseudo_id,

FORMAT_DATETIME('%x',

DATETIME(TIMESTAMP_MICROS

(user_first_touch_timestamp))) AS First_touch_DateTime,

event_date,

event_name,

COUNT(event_name) AS COUNT FROM `firebase-public-project.analytics_153293282.events_2018*`

WHERE (_TABLE_SUFFIX BETWEEN '0920' AND'1000')

AND event_name='session_start' GROUP BY user_pseudo_id,

First_touch_DateTime,

event_date,

event_name

(2) Second piece of code

The second part of the code summarizes all the user’s sessions for 10 days (the period we selected).

Using the example of user … 5401, line # 4, we see that this user, who first opened our application on August 30, 2018, has opened the application 22 times in the last 10 days.

Code to get this data:

-- ( 2 ) Second piece of code - The sum of sessions of a unique

-- user since the date of the first opening SELECT user_pseudo_id,

First_touch_DateTime,

SUM(COUNT) AS Sum_

FROM ( -- ( 1 ) First piece of code - The number of sessions of a unique

-- user on a specific day SELECT user_pseudo_id,

FORMAT_DATETIME('%x',

DATETIME(TIMESTAMP_MICROS

(user_first_touch_timestamp))) AS First_touch_DateTime,

event_date,

event_name,

COUNT(event_name) AS COUNT FROM `firebase-public-project.analytics_153293282.events_2018*`

WHERE (_TABLE_SUFFIX BETWEEN '0920' AND'1000')

AND event_name='session_start' GROUP BY user_pseudo_id,

First_touch_DateTime,

event_date,

event_name

) GROUP BY user_pseudo_id,

First_touch_DateTime

(3) Third piece of code

And finally, the third piece of code wraps all previously run queries, the final query groups the activity of users for the last 10 days by the date of the first opening.

For example, line # 1 — total users who first opened the application on December 31, 2017 year. Over the past 10 days, these users have made 27 sessions, with an average of 3.8 sessions per user.

A very loyal group of users), despite the fact that they almost joined us

A year ago, they still actively use the application.

The data is grouped by day, which is quite a suitable option if we use it to build a dashboard in Google Data Studio, where we will group the data by month. If you do not plan to build graphs and tabular data, it will be enough for you, then I would recommend avoiding unnecessary detail, and grouping the date of the first opening in a month and a year at once in the table. To do this, you just need to replace the date formatting code in the first part of the code:

FORMAT_DATETIME('%x',

DATETIME(TIMESTAMP_MICROS(

user_first_touch_timestamp)))

AS First_touch_DateTime

Change ‘% x’ to ‘% Y% B’ the date formatter now looks like:

FORMAT_DATETIME('%Y %B',

DATETIME(TIMESTAMP_MICROS(

user_first_touch_timestamp)))

AS First_touch_DateTime

As a result, we get the data in the form, the right image:

Full code to get this data: