atom-javascript coveralls travis-ci Bower karma npm

ironSource.atom SDK for Javascript at the browser

3 years after

ironSource.atom SDK for JavaScript

License Docs Coverage Status Build status Sauce Build Status

Browsers support

Sauce Test Status

atom-javascript is the official ironSource.atom SDK for Web Browsers.

Installation

Installation with Bower

$ bower install --save atom-sdk-js
<script src="bower_components/atom-sdk-js/dist/sdk.min.js"></script>

Installation with Atom CDN

To install a certain version just do:
<script src="https://js-sdk.atom-data.io/{VERSION_NUMBER_HERE}/sdk.min.js"></script>

For example:
<script src="https://js-sdk.atom-data.io/1.5.0/sdk.min.js"></script>
OR
<script src="https://js-sdk.atom-data.io/1.5.0/sdk.js"></script>

The CDN supports both HTTP and HTTPS 

Installation with async loading

<script type="text/javascript">
  (function(){
      var isa = document.createElement('script');
      isa.type = 'text/javascript';
      isa.async = true;
      isa.src = 'bower_components/atom-sdk-js/dist/sdk.min.js';
      // OR: isa.src = 'http://js-sdk.atom-data.io/1.5.0/sdk.min.js';
      (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(isa);
  })();
</script>

In case you use the async loading, your tracking code must be placed inside the following init function
See the example for more info.

<script type="text/javascript">
  window.IronSourceAtomInit = function() {
       // Your code here ...
  }
 </script>

Usage

High Level API - "Tracker"

The tracker is used for sending events to Atom based on several conditions

  • Every 30 seconds (default)
  • Number of accumulated events has reached 20 (default)
  • Size of accumulated events has reached 40KB (default)
var options = {
  endpoint: "https://track.atom-data.io/",
  auth: "YOUR_HMAC_AUTH_KEY", // Optional, depends on your stream config
  flushInterval: 10, // Optional, Tracker flush interval in seconds (default: 30)
  bulkLen: 50, // Optional, Number of events per bulk (batch) (default: 20) 
  bulkSize: 20 // Optional, Size of each bulk in KB (default: 40KB)
}

var tracker = new IronSourceAtom.Tracker(options); // Init a new tracker
var stream = "MY_STREAM_NAME"; // Your target stream name
var data = {id: 1, string_col: "String"}; // Data that matches your DB structure
tracker.track(stream, data); // Start tracking and empty the backlog on the described above conditions 

// To Flush all events:
tracker.flush(null, function (results) {
    // returns an array of results, for example:
    // data is: {"a":[{key: "value"}],"b":[{key: "value"}]}
    // result: [{"err":"Auth Error: \"a\"","data":null,"status":401} ,{"err":null,"data":{"Status":"OK"},"status":200}]
    //  NOTE: the results will be in the same order as the data.
}); // Send accumulated data immediately

// If you don't need the results, just do:
tracker.flush();
// OR to flush a single stream (optional callback)
tracker.flush(stream);

Low Level API

Sending a single event:

var stream = "MY.ATOM.STREAM";
var number = Math.random() * 3000 + 1;
var data = {
  event_name: "JS-SDK-PUT-EVENT-TEST",
  string_value: String(number),
  int_value: Math.round(number),
  float_value: number,
  ts: new Date()
};

var atom = new IronSourceAtom();
var params = { 
  data: data, 
  stream: stream,
  method: 'GET' // default is POST
};

atom.putEvent(params,
function (err, data, status) {
  console.log(err,data,status);
});

OR if you want to send a bulk(batch) of events:

var stream = "MY.ATOM.STREAM";
var data = [
  {"event_name":"JS-SDK-PUT-EVENTS-TEST","string_value":"67.217","int_value":67},
  {"event_name":"JS-SDK-PUT-EVENTS-TEST","string_value":"2046.43","int_value":20}
];
var atom = new IronSourceAtom();

atom.putEvents({ data: data, stream: stream },
function (err, data, status) {
    console.log(err,data,status);
});

Change Log

v1.5.0

Note: this version if fully compatible with the old ones except for the "Request" function which shouldn't be used directly on any case.

  • Refactor Tracker
    • Adding exponential backoff mechanism
    • Adding a taskMap to catch all tracker response
  • Refactoring response class
  • Adding new features and fixing example
  • Rewrote all tests
  • Fixing bugs in putEvent & putEvents methods
  • Adding Async loading
  • Adding CDN support
  • Changing the documentation to JSDOC.

v1.1.0

  • Fixed Auth mechanism
  • Adding Tracker

v1.0.1

  • Fixing the Javascript callback convention.
  • Updating docs
  • Updating Coverage

v1.0.0

  • Basic features: putEvent & putEvents functionalities

Example

You can use our example for sending data to Atom:

Example

License

MIT

Related Repositories

awesome-atom

awesome-atom

A curated list of delightful Atom packages and resources. ...

atom-beautify

atom-beautify

:lipstick: Beautification abstraction package for Atom editor ...

atom-in-orbit

atom-in-orbit

Putting Atom in the browser ...

atom-build

atom-build

:hammer: Build your project directly from the Atom editor ...

awesome-atom-packages

awesome-atom-packages

:package: Some Useful Atom Packages for Web Developers ! ...


Top Contributors

Jacckson zeevmoney shimont

Releases

-   1.5.0 zip tar
-   1.1.0 zip tar
-   1.0.1 zip tar
-   1.0.0 zip tar