Giter VIP home page Giter VIP logo

coveo.analytics.js's Introduction

coveo.analytics.js

Build Status Coverage Status Code Climate dev-dependencies license

Send events to the Coveo Analytics service. No external dependencies, pure JavaScript solution.

Service Api Documentation

Limitations

  • You can't have multiple sessions running. (cookies)
  • Works with IE9+ and recent versions of Firefox/Chrome/other...

Development

# 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

Deployment

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

Web Analytics Usage

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>

Usage

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'  
})

API

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.

coveo.analytics.js's People

Contributors

pastjean avatar wfortin avatar guisim avatar antoinebuteau avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.