Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
MarcoEidinger
Product and Topic Expert
Product and Topic Expert

Motivation


Do you develop mobile applications with SAP Cloud Platform SDK for iOS and Android and do you capture behavior events? Do you like the built-in analytical capabilities of SAP Cloud Platform Mobile Services but those are not sufficient?

In a previous blog post, I explained how to export client usage information in various ways.

In this blog post, I will show you how to build your own data visualization on top of such exported data. In particular, I will show you how to visualize your mobile user's flow in R.

As a BI tool, I will use SAP Analytics Cloud as it supports R visualization. You can request a free 30 day trial with SAP Analytics Cloud here.

P.S: Hopefully mobile user flow visualization will be supported as a built-in analytical option of SAP Cloud Platform Mobile Services in the future. Please like this blog post if you agree!

Step 0: Choose the type of visualization


There are multiple types of data visualization when it comes to behavior/user flow. The most common are Sankey and Sunburst diagrams.

In this blog post, I choose to use a Sunburst diagram. It is known as a multi-level pie chart or a radial treemap. Each ring shows hierarchy with the center being the root.



And rings can be sliced for each category


Step 1: Data Wrangling


A sunburst diagram is based on two vectors. One representing a sequence (of behavior events per session). The other representing the occurrence of such sequence across all sessions.















































Sequence Occurrence
ProductList-ProductDetails-End 111
ProductList-ProductDetails-Help-End 30
ProductList-ProductDetails-Order-End 99
ProductList-ProductDetails-FAQ-Order-End 12
OrderList-End 30
OrderList-CancelOrder-End 10
OrderList-ShippingStatus-End 20
ChatSalesRep-End 56
ChatSalesRep-Order-End 46
ChatSalesRep-CancelOrder-End 10

Looking at the exported data from SAP Cloud Platform Mobile Services it's clear that necessary information (behavior events) are present but not in the right data format.



I will use a python script to illustrate how to transform the downloaded client usage.

I will collect, per session, all behavior events of type "viewDisplayed" and store them in a single string separated by a dash (-). Then the transformed data model gets saved as a CSV file.
import pandas as pd

# read CPms raw data
df_rawData = pd.read_csv("/Path/of/your/exported/clientUsageFile.csv")
df_rawData = df_rawData.sort_values(by=['USERSESSIONID', 'RECORDTIMESTAMP'])
# drop unnecessary rows + columns
df_rawData = df_rawData[df_rawData.I_VIEW != '']
df_rawData = df_rawData[df_rawData.I_TYPE == 'viewDisplayed']
df_rawData = df_rawData.drop(columns=['REGISTRATIONID', 'RECORDTYPE', 'TIMERSTART', 'TIMERDURATION', 'I_SCREEN', 'I_RESULT', 'I_UNIT', 'I_MEASUREMENT', 'USER_NAME', 'I_CATEGORY', 'I_VALUE', 'I_CASE'])

# data model for target transformation
dataModelDic = {'session': [], 'sequence': [], 'occurrence': [], 'APPLICATIONID': [], 'APPLICATIONVERSION': [], 'DEVICEMODEL': [], 'DEVICEPLATFORM': [], 'DEVICEVERSION': []}

previousUserSessionId = ''
sequence = ""
occurrence = 0
for index, row in df_rawData.iterrows():

currentUserSessionId = row['USERSESSIONID']

if not previousUserSessionId: previousUserSessionId = currentUserSessionId

if previousUserSessionId != currentUserSessionId:
dataModelDic['session'].append(currentUserSessionId)
dataModelDic['sequence'].append(sequence)
sequence = ""
dataModelDic['occurrence'].append(occurrence)
occurrence = 1
previousView = ''
dataModelDic['APPLICATIONID'].append(row['APPLICATIONID'])
dataModelDic['APPLICATIONVERSION'].append(row['APPLICATIONVERSION'])
dataModelDic['DEVICEMODEL'].append(row['DEVICEMODEL'])
dataModelDic['DEVICEPLATFORM'].append(row['DEVICEPLATFORM'])
dataModelDic['DEVICEVERSION'].append(row['DEVICEVERSION'])

if not sequence:
sequence = row['I_VIEW']
else:
sequence = sequence + "-" + row['I_VIEW']

previousUserSessionId = currentUserSessionId

# save transformed data in CSV file
df_transformedData = pd.DataFrame(data=dataModelDic)
df_transformedData.to_csv('seq.csv')

Please note that the sample python script does not introduce a dedicated End event as this is optional.

Also, the sample script does not accurately set the occurrence count (it's always 1). This is ok in this case as duplicate sequence entry can be handled by the SunburstR library.

Step 2: Create R visualization


It's fairly simple to create a powerful and configurable sunburst diagram with R package sunburstR
library(sunburstR)

sequenceVector = c("ProductList-ProductDetails-End",
"ProductList-ProductDetails-Help-End",
"ProductList-ProductDetails-Order-End",
"ProductList-ProductDetails-FAQ-Order-End",
"OrderList-End",
"OrderList-CancelOrder-End",
"OrderList-ShippingStatus-End",
"ChatSalesRep-End",
"ChatSalesRep-Order-End",
"ChatSalesRep-CancelOrder-End")

frequencyVector = c(111, 30, 99, 12, 30, 10, 20, 56, 46, 10)

df <- data.frame(sequenceVector, frequencyVector)

sund2b(
df,
breadcrumbs = sund2bBreadcrumb(
enabled = TRUE
),
rootLabel = "Journey Start"
)

I chose to create test data inline in this R script but you can read from a CSV file or from a custom data source defined in SAP Analytics Cloud.

Step 3: Integrate R visualization in SAP Analytics Cloud


I am assuming you are already familiar with SAP Analytics Cloud and how to add new R Visualizations. There are several great blog posts like this blog from Andreas Forster.

Thankfully sunburstR is one of many pre-installed packages in the R server runtime environment service provided by SAP Analytics Cloud. For a complete list please check out this website.

I created the following video to showcase the necessary steps how to add such an R visualization in SAP Analytics Cloud.