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]:
Page Sessions Conversions
0 '/ 320 9
1 igostories.com/ 1381 448
2 igostories.com/?USA= 51 4
3 igostories.com/preview 224 163
4 staging.igostories.com/ 88 38

In [65]:
input_flow['CR'] = input_flow.Conversions / input_flow.Sessions * 100
input_flow


Out[65]:
Page Sessions Conversions CR
0 '/ 320 9 2.812500
1 igostories.com/ 1381 448 32.440261
2 igostories.com/?USA= 51 4 7.843137
3 igostories.com/preview 224 163 72.767857
4 staging.igostories.com/ 88 38 43.181818

In [66]:
d= input_flow.drop('Sessions', 1)
d


Out[66]:
Page Conversions CR
0 '/ 9 2.812500
1 igostories.com/ 448 32.440261
2 igostories.com/?USA= 4 7.843137
3 igostories.com/preview 163 72.767857
4 staging.igostories.com/ 38 43.181818

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]:
'igostories.com/preview'

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")


Loading BokehJS ...
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()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-68-8d9e0bdec7cc> in <module>()
     11 colors=cm.rainbow(np.random.rand(N))
     12 
---> 13 plt.scatter(conversions,cr,s=injuries,color=colors)
     14 for i in range(N):
     15     plt.annotate(page[i],xy=(conversions[i],cr[i]))

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
   3433                          vmin=vmin, vmax=vmax, alpha=alpha,
   3434                          linewidths=linewidths, verts=verts,
-> 3435                          edgecolors=edgecolors, data=data, **kwargs)
   3436     finally:
   3437         ax._hold = washold

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
   1889                     warnings.warn(msg % (label_namer, func.__name__),
   1890                                   RuntimeWarning, stacklevel=2)
-> 1891             return func(ax, *args, **kwargs)
   1892         pre_doc = inner.__doc__
   1893         if pre_doc is None:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   3956         y = np.ma.ravel(y)
   3957         if x.size != y.size:
-> 3958             raise ValueError("x and y must be the same size")
   3959 
   3960         if s is None:

ValueError: x and y must be the same size

In [ ]:


In [ ]:


In [ ]: