mirror of https://github.com/status-im/fathom.git
parse hostname from client instead of relying on http header. fixes #79
This commit is contained in:
parent
67308e3348
commit
9b47ee27ef
|
@ -68,17 +68,22 @@ function trackPageview() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the path or canonical
|
let req = window.location;
|
||||||
let path = location.pathname + location.search;
|
|
||||||
|
|
||||||
// parse path from canonical, if page has one
|
// parse canonical, if page has one
|
||||||
let canonical = document.querySelector('link[rel="canonical"][href]');
|
let canonical = document.querySelector('link[rel="canonical"][href]');
|
||||||
if(canonical) {
|
if(canonical) {
|
||||||
let a = document.createElement('a');
|
let a = document.createElement('a');
|
||||||
a.href = canonical.href;
|
a.href = canonical.href;
|
||||||
path = a.pathname;
|
|
||||||
|
// use parsed canonical as location object
|
||||||
|
req = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get path and pathname from location or canonical
|
||||||
|
let path = req.pathname + req.search;
|
||||||
|
let hostname = req.protocol + "//" + req.hostname;
|
||||||
|
|
||||||
// if parsing path failed, default to main page
|
// if parsing path failed, default to main page
|
||||||
if(!path) {
|
if(!path) {
|
||||||
path = '/';
|
path = '/';
|
||||||
|
@ -94,6 +99,7 @@ function trackPageview() {
|
||||||
const d = {
|
const d = {
|
||||||
sid: data.sid,
|
sid: data.sid,
|
||||||
p: path,
|
p: path,
|
||||||
|
h: hostname,
|
||||||
t: document.title,
|
t: document.title,
|
||||||
r: referrer,
|
r: referrer,
|
||||||
u: data.pagesViewed.indexOf(path) == -1 ? 1 : 0,
|
u: data.pagesViewed.indexOf(path) == -1 ? 1 : 0,
|
||||||
|
|
|
@ -25,10 +25,6 @@ func shouldCollect(r *http.Request) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Referer() == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,15 +75,10 @@ func (api *API) NewCollectHandler() http.Handler {
|
||||||
q := r.URL.Query()
|
q := r.URL.Query()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
hostname := parseHostname(r.Referer())
|
|
||||||
if hostname == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// get pageview details
|
// get pageview details
|
||||||
pageview := &models.Pageview{
|
pageview := &models.Pageview{
|
||||||
SessionID: q.Get("sid"),
|
SessionID: q.Get("sid"),
|
||||||
Hostname: hostname,
|
Hostname: parseHostname(q.Get("h")),
|
||||||
Pathname: parsePathname(q.Get("p")),
|
Pathname: parsePathname(q.Get("p")),
|
||||||
IsNewVisitor: q.Get("nv") == "1",
|
IsNewVisitor: q.Get("nv") == "1",
|
||||||
IsNewSession: q.Get("ns") == "1",
|
IsNewSession: q.Get("ns") == "1",
|
||||||
|
|
Loading…
Reference in New Issue