-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track some basic analytics with Keen.io
- Loading branch information
Showing
5 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
# https://github.com/ddollar/forego | ||
ASSET_HOST=localhost:3000 | ||
APPLICATION_HOST=localhost:3000 | ||
ASSET_HOST=localhost:3000 | ||
EXECJS_RUNTIME=Node | ||
KEEN_PROJECT_ID=replace_me | ||
KEEN_WRITE_KEY=replace_me | ||
PASSWORD=password | ||
PORT=3000 | ||
RACK_ENV=development | ||
RACK_MINI_PROFILER=0 | ||
SECRET_KEY_BASE=development_secret | ||
EXECJS_RUNTIME=Node | ||
SMTP_ADDRESS=smtp.example.com | ||
SMTP_DOMAIN=example.com | ||
SMTP_PASSWORD=password | ||
SMTP_USERNAME=username | ||
PASSWORD=password | ||
USERNAME=username | ||
WEB_CONCURRENCY=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
<% if ENV["SEGMENT_KEY"] %> | ||
<% unless Rails.env.test? %> | ||
<script src="https://d26b395fwzu5fz.cloudfront.net/3.4.1/keen.min.js" type="text/javascript"></script> | ||
<script type="text/javascript"> | ||
window.analytics=window.analytics||[],window.analytics.methods=["identify","group","track","page","pageview","alias","ready","on","once","off","trackLink","trackForm","trackClick","trackSubmit"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var key=window.analytics.methods[i];window.analytics[key]=window.analytics.factory(key)}window.analytics.load=function(t){if(!document.getElementById("analytics-js")){var a=document.createElement("script");a.type="text/javascript",a.id="analytics-js",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)}},window.analytics.SNIPPET_VERSION="2.0.9", | ||
window.analytics.load("<%= ENV["SEGMENT_KEY"] %>"); | ||
window.analytics.page(); | ||
|
||
var keenClient = new Keen({ | ||
projectId: "<%= ENV.fetch('KEEN_PROJECT_ID') %>", | ||
writeKey: "<%= ENV.fetch('KEEN_WRITE_KEY') %>", | ||
}); | ||
|
||
var pageLoadDate = new Date(); | ||
var pageLoadTime = pageLoadDate.getTime(); | ||
|
||
var pageData = { | ||
client_ip: <%= request.remote_ip.inspect.html_safe %>, | ||
params: <%= params.to_json.html_safe %>, | ||
page_controller_path: "<%= [params[:controller], params[:action]].join('.') %>", | ||
referrer: document.referrer, | ||
browser: bowser, | ||
keen: { | ||
timestamp: pageLoadDate.toISOString() | ||
} | ||
}; | ||
|
||
keenClient.addEvent("Page Load", pageData); | ||
|
||
window.onbeforeunload = function (event) { | ||
pageData.timeSpentInMilliseconds = new Date().getTime() - pageLoadTime; | ||
keenClient.addEvent("Page Unload", pageData); | ||
} | ||
</script> | ||
<% end %> |