Use the category partition in the function

Hi,

I’m doing some analytics on a mobile app. Currently I’m processing how many times a user has entered into a screen inside the app. But the problem is that the system is partitioned by clientId at the highest level. So to achieve multi tenancy currently I’m ending all my streams with ‘-{clientId}’.

So let’s say I have following event format for VisitedScreen event in stream ‘analytics-1’:

{
“name”: “VisitedScreen”,
“screenName”: “Newsfeed”,
“year”: 2016,
“month”: 10
}

The 1 in anaylitics-1 is the clientId.

and I partition this by year.

fromCategory(‘analytics’)
.foreachStream()
.when({
“VisitedScreen”: function(state, ev) { linkTo(‘analytics_year-’+ev.body.year+’-1’, ev); }
});

This succesfully creates a new stream as expected, but the clientId inside the function is hardcoded. How can I get the cliendId (the partition) from within the function, or am I going about this completely wrong.

Regards

put it event / metadata

Alright thanks.

Also why do you need a state per stream here (eg foreachStream) you
are not using state as far as I can tell

You’re right, actually the example was wrong. The one above is actually using fromStream to partition by year and month. The real one uses state as below.

function(state, ev) {
initScreenName(state, ev.body.screenName);
state[ev.body.screenName].count += 1;
}

``