Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit c145f84

Browse files
author
Mike Ng
committed
Add environment detection to event builder so it can distinguish between events sent from node or the browser.
1 parent 4d6b0e8 commit c145f84

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

CHANGELOG

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
-------------------------------------------------------------------------------
2+
0.1.3
3+
-------------------------------------------------------------------------------
4+
* Add environment detection to event builder so it can distinguish between events sent from node or the browser.
5+
-------------------------------------------------------------------------------
6+
17
-------------------------------------------------------------------------------
28
0.1.2
39
-------------------------------------------------------------------------------
4-
* Update travis and coveralls settings post open sourcing
10+
* Update travis and coveralls settings post open sourcing.
511
-------------------------------------------------------------------------------
612

713
-------------------------------------------------------------------------------

lib/core/event_builder/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('lodash/core');
2+
var environmentUtils = require('../../utils/environment');
23
var packageJSON = require('../../../package.json');
34
var sprintf = require('sprintf');
45

@@ -52,7 +53,11 @@ function getCommonParams(configObj, userId, attributes) {
5253
_.assignIn(params, attributeParams);
5354
}
5455

55-
params[urlParams.source] = sprintf('node-sdk-%s', packageJSON.version);
56+
// determine which SDK to attribute to based on the environment the code is
57+
// executing in
58+
var sdkName = environmentUtils.isNode() ? 'node-sdk' : 'javascript-sdk';
59+
60+
params[urlParams.source] = sprintf('%s-%s', sdkName, packageJSON.version);
5661
params[urlParams.time] = Math.round(new Date().getTime() / 1000.0);
5762
return params;
5863
}

lib/utils/environment/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
/**
3+
* Determines if the code is executing in a node environment
4+
* @return {Boolean} true if the code is running in a node env
5+
*/
6+
isNode: function() {
7+
return typeof window === 'undefined'
8+
&& typeof process === 'object';
9+
},
10+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "optimizely-server-sdk",
33
"description": "Node SDK for consumption for server-side testing",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/optimizely/node-sdk.git"

0 commit comments

Comments
 (0)