Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
stream-analytics
Advanced tools
The best way to add the client to your application is to load it asyncronously. You can paste the following snippet anywhere in the HTML and the client will load without interfering with the page load.
<script type="text/javascript">
!function(a,b){a("StreamAnalytics","//d2j1fszo1axgmp.cloudfront.net/2.0.0/stream-analytics.min.js",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]=function(b){c["_"+a].clients=c["_"+a].clients||{},c["_"+a].clients[b.projectId]=this,this._config=b},d=["setUser","trackImpression","trackEngagement"];for(var g=0;g<d.length;g++){var h=d[g],i=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};c[a].prototype[h]=i(h)}e=document.createElement("script"),e.async=!0,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
</script>
In your project directory run:
npm install stream-analytics --save
To use the client in your project require it by using the package name:
var StreamAnalytics = require('stream-analytics');
Once your application is enabled to use Stream's Analytics platform, you will get an API_KEY
and a token
to access the APIs. Reach support@getstream.io to set that up.
Analytics tracking is done using a client object, here's the code that initializes it.
var client = new StreamAnalytics({
apiKey: "API_KEY",
token: "ANALYTICS_TOKEN"
});
Before you can track events, you need to set the current user. All analytics events are related to the users of your application.
client.setUser('7b22b0b8-6bb0-11e5-9d70-feff819cdc9f');
Everytime you display content to the user, you should track the impression. The trackImpression
method allows you to track what content is displayed to the user. There are 2 required fields that you need to provide:
Here's an example of how you would track the display of the "user:ChartMill" feed to the current user, the example implies that the user was presented with a list of contents: one message with ID 34349698 and one comment with ID 414416008. Using a combiantion of content_type and ID is a very simple way to avoid collision between objects of different types.
var impression = {
foreign_ids: ['message:34349698', 'comment:414416008'],
feed_id: 'user:ChartMill'
};
// track impression for two messages presented to the user
client.trackImpression(impression);
You can find a comprehensive list of all optional parameters that you can send with the trackImpression
method in the API reference docs.
User interactions are tracked using the trackEngagement
method, the mechanism is very similar to trackImpressions
.
An engagement event is composed by the following fields:
// Click on a message
var engagement = {
label: 'click',
foreign_id: 'message:34349698',
feed_id: 'user:ChartMill'
};
client.trackEngagement(engagement, function(){console.log(arguments);});
// Share message
var engagement = {
label: 'share',
foreign_id: 'message:34349698',
feed_id: 'user:ChartMill'
};
client.trackEngagement(engagement);
You can get more information out of analytics by adding extra information regarding impressions and engagements. Below you can fine the list of additional fields that you can provide to both trackEngagement
and trackImpression
methods.
An integer that multiplies the score of the interaction (eg. 2 or -1)
If necessary, you can send additional information about the data involved or the specific event. The features field must be a list of feature objects. A feature object is made of two mandatory fields: "group" and "value"
eg.
[{
'group': 'topic',
'value': 'coffee'
}]
A string representing the location of the content (eg. 'notification_feed')
When tracking interactions with content, it might be useful to provide the oridinal position (eg. 2)
A string representing the location of the content (eg. 'notification_feed')
A string representing the location of the content (eg. 'notification_feed')
FAQs
Analytics JS client for GetStream.io.
The npm package stream-analytics receives a total of 4,098 weekly downloads. As such, stream-analytics popularity was classified as popular.
We found that stream-analytics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.