Skip to content

Commit 774611d

Browse files
committed
First attempt at basic hash tracking. Refs #445.
1 parent 4dc77c6 commit 774611d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

media/javascript/rtd.js

+43
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,31 @@
5353
}
5454
};
5555

56+
function logHashChange(project, version, page, id, hash) {
57+
$.ajax({
58+
type: 'POST',
59+
url: 'http://api.grokthedocs.com/api/v1/actions/',
60+
crossDomain: true,
61+
data: {
62+
project: project,
63+
version: version,
64+
page: page,
65+
object_slug: id,
66+
hash: hash,
67+
url: window.location.href,
68+
type: "hashchange"
69+
},
70+
success: function(data, textStatus, request) {
71+
console.log("Sent hash change data")
72+
},
73+
error: function(request, textStatus, error) {
74+
console.log("Error sending hash change data")
75+
}
76+
});
77+
}
78+
5679
$(function () {
80+
// Code executed on load
5781
var slug = window.doc_slug,
5882
version = window.doc_version;
5983

@@ -68,6 +92,25 @@
6892

6993
checkVersion(slug, version);
7094
getVersions(slug, version);
95+
96+
97+
// Click tracking code
98+
window.onhashchange = function(ev) {
99+
var element = document.getElementById((window.location.hash || '').slice(1))
100+
var project = doc_slug
101+
var version = doc_version
102+
var page = page_name
103+
var id = element.id
104+
if (typeof element.hash != "undefined") {
105+
var hash = element.hash
106+
} else {
107+
var hash = null
108+
}
109+
logHashChange(project, version, page, id, hash);
110+
}
111+
112+
113+
71114
});
72115

73116
})();

0 commit comments

Comments
 (0)