Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding returning visitors, os, browsers on the dashboard #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions web/controllers/metric_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,109 @@ def report_site_visits(self, args):
def report_domains(self, args):
return self.get_site_hostnames(args.get('token'))

def report_returning_visitors(self, args):

s = self.Session()
since = datetime.utcnow() - timedelta(30)
until = datetime.utcnow()
token = args.get('token')
domain = args.get('domain')
options = {
'site_key': token,
'since': since,
'until': until,
'domain': domain,
}

query = '''
SELECT extract(epoch from date_trunc('day', ts)) AS day,
count(message->>'returning_from_ts')
FROM messages WHERE
message->>'returning_from_ts' is not null AND
message->>'type' ='site_visit_by_day' AND
site_id = (SELECT site_id FROM sites WHERE site_key = :site_key) AND
message->>'p' LIKE :domain AND
ts >= :since AND
ts < :until
GROUP BY
day;
'''

grouped_counts = s.execute(query,options).fetchall()
return [[int(ts), count] for ts, count in grouped_counts]

def report_os(self, args):

s = self.Session()
token = args.get('token')

options = {
'site_key': token
}

query = '''
select message->>'os' as os, count(1) as count
from messages WHERE
message->>'os' is not null AND
message->>'type'='new_year' AND
site_id = (SELECT site_id FROM sites WHERE site_key = :site_key)
GROUP BY os
ORDER BY count DESC
LIMIT 5
'''

grouped_counts = s.execute(query,options).fetchall()

return [[ua, count] for ua, count in grouped_counts]

def report_ua(self, args):

s = self.Session()
token = args.get('token')

options = {
'site_key': token
}

query = '''
select message->>'browser' as browser, count(1) as count
from messages WHERE
message->>'browser' is not null AND
message->>'type'='new_year' AND
site_id = (SELECT site_id FROM sites WHERE site_key = :site_key)
GROUP BY browser
ORDER BY count DESC
LIMIT 5
'''

grouped_counts = s.execute(query,options).fetchall()

return [[ua, count] for ua, count in grouped_counts]

def report_top_pages(self, args):

s = self.Session()
token = args.get('token')
domain = 'http%://' + args.get('domain') + '%'
options = {
'site_key': token,
'domain': domain
}

query = '''
select message->>'p' as p, count(1) as count
from messages WHERE
message->>'type'='page_visit_by_year' AND
message->>'p' LIKE :domain AND
site_id = (SELECT site_id FROM sites WHERE site_key = :site_key)
GROUP BY p
ORDER BY count DESC
LIMIT 5
'''

grouped_counts = s.execute(query,options).fetchall()

return [[ua, count] for ua, count in grouped_counts]
def messages_per_interval(self, token, message_type,
interval_size='day',
domain=None):
Expand Down Expand Up @@ -101,6 +204,7 @@ def messages_per_interval(self, token, message_type,

grouped_counts = s.execute(query, options).fetchall()

print grouped_counts
return [[int(ts), count] for ts, count in grouped_counts]

def get_site_hostnames(self, token, since=datetime.utcnow() - timedelta(30),
Expand Down
26 changes: 25 additions & 1 deletion web/static/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(function () {
show: true,
barWidth: (response.period == 'daily' ? 24 * 60 * 60 * 1000 : 24 * 60 * 60 * 7 * 1000),
fillColor: green,
lineWidth: 1,
lineWidth: 0,
align: "center",
};

Expand All @@ -53,6 +53,30 @@ $(function () {
});
});

// e.click(function() {
// window.location = "/metric_konark/" + e.data('metric') + '/';
// })
});


$("div.tabular").each(function (index, elem) {
var e = $(elem);

var url = "/metric_details?token=" + token + "&name=" + e.data('metric') + "&domain=" + site;
//var url = "http://192.168.5.239/dashboard_json_files/" + e.data('metric') + ".json";
//var url = "konark.php?url=http://192.168.5.239/dashboard_json_files/" + e.data('metric') + ".json";
$.getJSON(url, function(response) {
console.log(response);
// table = `<table>`;
table = '';
response.data.forEach( e => {
table += `<b>${e[0]} :</b> ${e[1]}<br/>`;
});

// table += `</table>`;
e.html(table);
});

// e.click(function() {
// window.location = "/metric_konark/" + e.data('metric') + '/';
// })
Expand Down
48 changes: 44 additions & 4 deletions web/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ <h3>Unique Visitors</h3>
<div class="sparkline" id="1" data-metric="site_uv" style="padding: 0px;"></div>
</div>

</div>

<div class='dashboard-index'>
<div class="metric has-sparkline">
<h3>Site loads</h3>
<div>
Expand All @@ -58,7 +55,6 @@ <h3>Site loads</h3>
<div class="sparkline" id="1" data-metric="site_visits" style="padding: 0px;"></div>
</div>

<div class='dashboard-index'>
<div class="metric has-sparkline">
<h3>Page views</h3>
<div>
Expand All @@ -71,6 +67,50 @@ <h3>Page views</h3>

<div class="sparkline" id="1" data-metric="page_load" style="padding: 0px;"></div>
</div>
<div class="metric has-sparkline">
<h3>Daily Returning Visitors</h3>
<div>
<div class="value">
-
</div>
<div class="timestamp">Total</div>
</div>


<div class="sparkline" id="1" data-metric="returning_visitors" style="padding: 0px;"></div>
</div>
</div>


<div class='dashboard-index'>
<div class="metric has-sparkline">
<h3>OS</h3>
<div>
<div class="tabular" data-metric="os">
</div>
</div>
</div>
</div>

<div class='dashboard-index'>
<div class="metric has-sparkline">
<h3>Browsers</h3>
<div>
<div class="tabular" data-metric="ua">
</div>
</div>
</div>
</div>

<div class='dashboard-index'>
<div class="metric has-sparkline">
<h3>Top Pages</h3>
<div>
<div class="tabular" data-metric="top_pages">
-
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/templates/template_landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h2>Try it</h2>


<h4>Accessing Dashboard</h4>
<p> <a href='#'>{{ context.dashboard }}?token={{ context.site_key }}</a> ,
<p> <a href="{{ context.dashboard }}?token={{ context.site_key }}">{{ context.dashboard }}?token={{ context.site_key }}</a> ,
<br/>If you lose this link, you will have to regenerate the tokens.
<p class="important">
<p><a href="{{ context.dashboard }}?token={{ context.site_key }}" rel="sidebar" title="Dashboard Green Analytics">Dashboard Token: {{ context.site_key }}</a></p>
Expand Down