Skip to content

griffinmichl/event-tracker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Behold, the Event Tracker

Build Status

Usage:

// key, secret, clientName, and endpoint can also be configured via the environment
// variables TRACKER_KEY, TRACKER_SECRET, TRACKER_CLIENT_NAME and TRACKER_ENDPOINT.

var tracker = new EventTracker({
  key: 'MyApp01',
  secret: 'abcdef==',
  postData: jQuery.post, // function to use for ajax: `post(url, data)`
  calculateHash: createHmac, // A function that takes (key, string) and returns an HMAC
  endpoint: 'https://events-test.redditmedia.com/v1', // collector endpoint
  clientName: 'desktopWeb', // client name, prepended to event type in payload
  appendClientContext: true, // automatically adds user_agent, path, and domain to payload
  bufferTimeout: 100, // flush buffer of events after 100ms
  bufferLength: 40, // flush buffer events after buffer length is 40
  debug: true, // log events instead of sending them.
);

tracker.track('mod_events', 'ban', {
  user_name: 'allthefoxes',
  user_id: 't2_8aioi',
  sr_name: 'noadmins',
  sr_id: 't5_2xakt',
  details_text: 'reason: being an admin',
  target_id: 't2_3bzrh',
  target_name: 'ajacksified',
  target_type: 'user',
}, defaults);

// send immediately rather than buffering. Without calling `send()`, the event
// will be sent after buffer timeout (100ms) or buffer max length (40) is
// reached. `send` flushes the current buffer of events and resets the timer.
// send optionally takes a callback.
tracker.send(callback);

Testing

  • Install node
  • Run npm test

Using It

  • Either use it as a git-linked NPM package, copypaste it into your project, or git-submodule it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%