Send events to the Coveo Analytics service. No external dependencies, pure JavaScript solution.
- You can't have multiple sessions running. (cookies)
- Works with
IE9+
and recent versions ofFirefox/Chrome/other...
# install development dependencies
npm install
# Check standard respects (tabs and spaces should be automatic if your editor
# supports editorconfig http://editorconfig.org/)
npm run lint
# Run tests automatically (open your browser on http://localhost:9876 )
npm run testlive
# Wanna see other available tasks
# just run:
npm run
publish your version tag and update latest
tag
git tag -a v0.0.0 -m "v0.0.0 new features =D"
# -f needed to override tag locally and when pushing
git tag -f -a latest -m "v0.0.0"
git push -f --tags
By the way, if you need to log analytics on any web page, add this snippet in your page.
<script>
(function(k,r,y,p,t,o,n){
n='CoveoAnalytics';k[n]=k[n]||function(){(k[n].q=k[n].q|| []).push(arguments)};
k[n].t=Date.now();o=r.createElement(y);o.async=1;o.src=p;
t=r.getElementsByTagName(y)[0];t.parentNode.insertBefore(o,t)
})(window,document,'script','https://static.cloud.coveo.com/coveo.analytics.js/latest/coveo.analytics.js')
CoveoAnalytics('init','00000000-YOUR-ToKe-N000-000000000000');
CoveoAnalytics('send','pageView')
</script>
add script in your page:
<script src="https://static.cloud.coveo.com/ua/0.1.0/coveo.analytics.min.js"></script>
in the Browser:
// works with or without new
// the token can be retrieved by contacting Coveo Support
var ua = Coveo.UA({token: 'your-token-here'})
ua.sendCustomEvent({
eventType: 'Your Custom Event Type',
eventValue: 'Your Custom Event Value'
})
CoveoAnalytics(options): instantiate a new analytics event logger
var options = {
token: '' // required
endpoint: '' // optional: defaults to https://usageanalytics.coveo.com/rest/v13/analytics
}
CoveoAnalytics.getStatus(callback): gets the status of the analytics service
// https://usageanalytics.coveo.com/docs/#!/v13_analytics/getServiceStatus
var callback = function(data){
// Format of data: { status: '' }
console.log(data.status)
}
CoveoAnalytics.sendSearchEvent(data, callback): user searched something
var data = {/* https://usageanalytics.coveo.com/docs/#!/v13_analytics/addSearchEvent */}
var callback = function(){
console.log('logged event')
}
CoveoAnalytics.sendSearchEvents(data, callback): sends multiple search events
//
var data = [/* https://usageanalytics.coveo.com/docs/#!/v13_analytics/addSearchEvents */]
var callback = function(){
console.log('logged a lot of events')
}
CoveoAnalytics.sendClickEvent(data, callback): user clicked on something
// Required params are here
// You can find others at: https://usageanalytics.coveo.com/docs/#!/v13_analytics/addClickEvent
var data = {
"actionCause":"documentOpen",
"searchQueryUid":"dc39ef98-f06c-48f9-8c61-3425714b8fc0",
"documentUri":"http://uri.com",
"documentUriHash":"4p1+Qt7oxARhuldx",
"sourceName":"That coveo Source",
"documentPosition":0,
}
var callback = function(resp){
console.log('logged event with', resp)
}
CoveoAnalytics.sendCustomEvent(data, callback): send events other than click/search
// Required params are here
// You can find others at: https://usageanalytics.coveo.com/docs/#!/v13_analytics/addCustomEventViaPost
var data = {
eventType: 'theeventtype',
eventValue: 'eventvalue'
};
var callback = function(resp){
console.log('logged event with', resp)
}
CoveoAnalytics.deleteSession(): clears cookies, you lose your visitor id and your current session is stopped. Next queries will get you a new one.