Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-analytics

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-analytics

Analytics JS client for GetStream.io.

  • 2.0.0-alpha
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
decreased by-1.16%
Maintainers
1
Weekly downloads
 
Created
Source

Get the library

Load the library asynchronously

<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>

Configure an instance for your project

var client = new StreamAnalytics({
  apiKey: "API_KEY",
  token: "ANALYTICS_TOKEN"
});

Set current user

client.setUser('7b22b0b8-6bb0-11e5-9d70-feff819cdc9f');

Track impressions

Every activity (eg. messages) shown to the user should be tracked as an impression.

var impression = {
    foreign_ids: ['message:34349698'],
    feedId: 'user:ChartMill'
};

// track impression for two messages presented to the user
client.trackImpression(impression);

Engagement tracking

Every meaningful user interactions should be tracked with a label, optional extra information can be tracked as well.

engagement = {...}
// Sends one engagement event to the APIs
client.trackEngagement(engagement);

// Click on a message
var engagement = {
    label: 'click',
    foreignId: 'message:34349698',
    feedId: 'user:ChartMill'
};
client.trackEngagement(engagement, function(){console.log(arguments);});

// Share message
var engagement = {
    label: 'share',
    foreignId: 'message:34349698',
    feedId: 'user:ChartMill'
};
client.trackEngagement(engagement);

Fields reference

features

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'
}]

location

A string representing the location of the content (eg. 'notification_feed')

feed_id

A string representing the origin feed for the content

boost

An integer that multiplies the score of the interaction (eg. 2 or -1)

position

When tracking interactions with content, it might be useful to provide the oridinal position (eg. 2)

foreign_id

The ID for the content as you store that in your database (or/and on Stream's feeds) (eg. 'user:42') (engagement only)

foreign_ids

An Array of foreign_ids (impressions only)

label

The event identifier (eg. click, share, ...) this field is mandatory for every engagement event

Keywords

FAQs

Package last updated on 05 Oct 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc