Skip to content

Commit

Permalink
Merge pull request #1 from codeniko/improve-coverage
Browse files Browse the repository at this point in the history
improve code coverage & test codecov/travis on PRs
  • Loading branch information
Nikolay Feldman authored May 5, 2018
2 parents dfb8a76 + c319a5e commit fcdd8eb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ All Configurations
-----
```javascript
tracker.push({
endpoint: '/ENDPOINT', // endpoint to send tracking data to
sendCaughtExceptions: true/false, // send exceptions caught by browser. DEFAULT: true
attachClientContext: true/false, // attach various client context, such as useragent, platform, and page url. DEFAULT: true
sessionId: 'SESSION_ID', // explicitly set a session id
devMode: true/false // toggle dev mode. If enabled, outgoing requests are blocked and logged for debugging instead. DEFAULT: false
endpoint: '/ENDPOINT', // Endpoint to send tracking data to
sendCaughtExceptions: true/false, // Send exceptions caught by browser. DEFAULT: true
attachClientContext: true/false, // Attach various client context, such as useragent, platform, and page url. DEFAULT: true
sessionId: 'SESSION_ID', // Explicitly set a session id
devMode: true/false // Toggle dev mode. If enabled, outgoing requests are blocked and logged for debugging instead. DEFAULT: false
});
```

Expand Down Expand Up @@ -203,7 +203,7 @@ tracker.push({

Bugs, feature requests, & contributing
-----
If you found a bug or want to request a feature, [create a new issue](https://github.com/codeniko/simple-tracker/issues). Contributions are more than welcome :)
If you found a bug or want to request a feature, [create a new issue](https://github.com/codeniko/simple-tracker/issues). Contributions via pull requests are more than welcome :)

Running unit tests and code coverage
----------
Expand Down
2 changes: 1 addition & 1 deletion dist/simple-tracker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/simple-tracker.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
(function() {
'use strict'

function simpleTracker(window, document) {
function simpleTracker(window) {
var SESSION_KEY = 'trcksesh'
var SESSION_KEY_LENGTH = SESSION_KEY.length + 1

var document = window.document
var sendCaughtExceptions = true
var attachClientContext = true
var devMode = false
Expand Down Expand Up @@ -81,12 +82,7 @@
xmlHttp.open('POST', endpoint, true) // true for async
xmlHttp.setRequestHeader('Content-Type', 'application/json')
xmlHttp.send(JSON.stringify(data))
} catch(ex) {
if (window.console && typeof window.console.log === 'function') {
console.log('Failed to send tracking request because of this exception:\n' + ex)
console.log('Failed tracking data:', data)
}
}
} catch(ex) { }
} else {
console.debug('SimpleTracker: POST ' + endpoint, data)
}
Expand Down Expand Up @@ -149,13 +145,12 @@
startTimer: function(metric) {
var performance = window.performance
if (performance.now) {
if (timer[metric]) {
/* istanbul ignore if */
if (timer[metric] && devMode) {
console.warn("Timing metric '" + metric + "' already started")
}
console.debug('timer started for:', metric)
devMode && console.debug('timer started for:', metric)
timer[metric] = performance.now()
} else {
console.warn('window.performance is not defined')
}
},

Expand All @@ -164,13 +159,14 @@
if (performance.now) {
var stopTime = performance.now()
var startTime = timer[metric]
/* istanbul ignore else */
if (startTime !== undefined) {
var diff = Math.round(stopTime - startTime)
timer[metric] = undefined
console.debug('timer stopped for:', metric, 'time=' + diff)
devMode && console.debug('timer stopped for:', metric, 'time=' + diff)
this.logMetric(metric, diff)
} else {
console.warn("Timing metric '" + metric + "' wasn't started")
devMode && console.warn("Timing metric '" + metric + "' wasn't started")
}
}
},
Expand Down Expand Up @@ -228,10 +224,7 @@

var existingTracker = window.tracker // either instance of SimpleTracker or existing array of events to log that were added while this script was being loaded asyncronously

// reuse SimpleTracker instance if already created
if (existingTracker && existingTracker instanceof SimpleTracker) {
tracker = existingTracker
} else if (existingTracker && existingTracker.length) {
if (existingTracker && existingTracker.length) {
// move all from existing and push into our tracker object
tracker = new SimpleTracker()
var i = 0
Expand All @@ -248,10 +241,10 @@
return tracker
}


var isModule = typeof module !== 'undefined' && module.exports
/* istanbul ignore else */
if (typeof window !== 'undefined') {
var tracker = simpleTracker(window, window.document) // sets window.tracker
var tracker = simpleTracker(window) // sets window.tracker
if (isModule) {
simpleTracker.default = tracker
module.exports = tracker
Expand Down
Loading

0 comments on commit fcdd8eb

Please # to comment.