In [61]:
%matplotlib inline
import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import pandas as pd
pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 100)
pd.set_option('display.notebook_repr_html', True)
import seaborn as sns #sets up styles and gives us more plotting options
In [62]:
# Time period 1st Jan - 30th April (arbitrary )
# API credentials
# Email address 705762800217-compute@developer.gserviceaccount.com
# Key IDs 948ee8e2a420ef14a5d5a29bd35104fe2f1e6ed4
In [63]:
# open file. It is requested via API explorer using request parameters:
#Account: IGoStories
#Property: IGoStories
#View: 03 Raw Data
#ids: ga:133544473
#start-date: 2017-02-01
#end-date: 2017-04-30
#metrics
#ga:sessions
#ga:sessionsWithEvent
#dimensions
#ga:pagePath
#sort
#-ga:sessionsWithEvent
#filter
#ga:sessions>10
In [64]:
input_flow= pd.read_csv('data/iGo.csv')
# rename columns
input_flow.columns=['Page','Sessions','Conversions']
# filter page with CR > 0
input_flow = input_flow[input_flow.Conversions > 0]
# group by page
input_flow_index = input_flow.set_index('Page')
input_flow
Out[64]:
In [65]:
input_flow['CR'] = input_flow.Conversions / input_flow.Sessions * 100
input_flow
Out[65]:
In [66]:
d= input_flow.drop('Sessions', 1)
d
Out[66]:
In [67]:
input_flow_cr = input_flow.set_index('CR')
max_CR = max(input_flow.CR)
best_page = input_flow_cr.loc[max_CR,'Page']
best_page
Out[67]:
In [69]:
from bokeh.io import output_notebook
from bokeh.charts import Bar, Line, show
from bokeh.plotting import figure, output_file, show
output_notebook()
p = Bar(input_flow, 'Page', values='CR', title="The best converting page on your site is %s" % best_page)
p.legend.location = "top_right"
show(p)
print("Put an additional button \"Contact Us\" on the main page. (or adding the contact form link to the menu bar at the top of the homepage")
In [68]:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
page=d['Page']
convesions = d['Conversions']
cr = d['CR']
injuries = [1625,1752,1629,2255,1630]
colors=cm.rainbow(np.random.rand(N))
plt.scatter(conversions,cr,s=injuries,color=colors)
for i in range(N):
plt.annotate(page[i],xy=(conversions[i],cr[i]))
plt.xlabel('Conversions')
plt.ylabel('CR')
# Move title up with the "y" option
plt.title('USER FLOW',y=1.05)
plt.show()
In [ ]:
In [ ]:
In [ ]: