Activity operations
Manage user activity with these methods.
Activity operations are related to user's actions. Actions can be like, dislike, add, page view and etc.
The namespace is of course called activity. All methods return promises. The general design of the namespace follows this pattern unless stated otherwise:
sdk.activity
.someMethod(filtersObject)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
The responses are comprised of different objects you can find here.
For all following examples in tags argument our sport provider will be native.
For more information visit FansUnitedSDK integration
General operations
Add new activity for user
Method: add(action, tags, content?, campaign?)
Method creates activity for specific user. Needs authentication.
Arguments are as they follow:
- action: enum. Options are:
- like
- dislike
- page_view
- content_consumed
- share
- comment
- click_ad
- conversion
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.add('share', tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "share",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Delete specific activity
Method: delete(activityId)
Deletes specific activity owned by the user. Returns true
for successful execution.
sdk.activity
.delete('2c150d0c-9ed5-4fd1-adb4-37d1357b822d')
.then((responseBoolean) => {
// do something with responseBoolean
})
.catch((error) => {
// handle error
});
Alias operations
All actions for method add() are extracted in alias methods for more friendly development. They all accept same arguments and return same response.
Add "Like" activity
Method: like(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.like(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "like",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Dislike" activity
Method: dislike(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.dislike(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "dislike",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Pageview" activity
Method: addPageview(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addPageview(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "page_view",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Content consumed" activity
Method: addContentConsumed(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addContentConsumed(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "content_consumed",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Share" activity
Method: addShare(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addShare(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "share",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Comment" activity
Method: addComment(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addComment(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "comment",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Clicked ad" activity
Method: addClickAd(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addClickAd(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "click_ad",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Add "Conversion" activity
Method: addConversion(tags, content?, campaign?)
Arguments are as they follow:
- tags: a list of TagsModel. Competitions, players, teams or matches that user has made an action with.
- content: ContentModel. Optional. For example the content can be an article about a match between two teams in one competition.
- campaign: CampaignModel. Optional. User can interact in some campaign.
const tags = [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
];
const content = {
type: "article",
id: "35135151",
label: "Benzema scores against Barcelona again to secure 2:0 win",
};
const campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here",
}
sdk.activity
.addConversion(tags, content, campaign)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
{
id: "2c150d0c-9ed5-4fd1-adb4-37d1357b822d",
profileId: "LeRGY3cQ9Bd4nKslDwKrhzWXdvl1",
action: "conversion",
context: {
content: {
id: "35135151",
type: "article",
label: "Benzema scores against Barcelona again to secure 2:0 win"
},
tags: [
{
source: 'football',
type: 'team',
id: 'fb:t:8102',
},
{
source: 'football',
type: 'competition',
id: 'fb:c:3',
},
{
source: 'football',
type: 'player',
id: 'fb:p:43400',
},
],
campaign: {
id: "your-campaign-id-here",
label: "your-campaign-label-here"
}
},
points: 10
}
Profile activities
Get user's own activities
Method: getOwn(filters?, disableCache?)
Returns the activities for the current logged in user. The response is paginated.
By default the request is cached by API for 1 hour so JavaScript SDK accepts disableCache
argument. It's a boolean
and if provided the response will NOT be cached.
Filters argument accept the following options:
- action.
enum
. All provided actions are described here. - page.
number
. The number of the page. - limit.
number
. Determines how many items per page there will be.
const userId = "userId";
const filters = {
action: 'like',
page: 2,
limit: 1,
};
const disableCache = true;
sdk.activity
.getOwn(filters, true)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
meta: {
pagination: {
currentPage: 2,
itemsPerPage: 1,
totalItems: 257697,
numberOfPages: 12885
}
},
data: [
{
id: "c83b127a-3238-4b1d-8f6d-1db2851fafe0",
profileId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
action: "like",
context: {
content: {
id: "123131",
type: "article",
label: "asd123"
},
tags: [
{
id: "football",
type: "team",
source: "fb:t:8102"
},
{
id: "football",
type: "competition",
source: "fb:c:3"
},
{
id: "football",
type: "player",
source: "fb:p:43400"
}
],
campaign: {
id: "your-campaign-id-here",
label: "Carlsberg 2022"
}
},
points: 10
}
]
Get user's activities
Method: getForUser(userId, filters?, disableCache?)
Returns the activities for specific user. The response is paginated.
By default the request is cached by API for 1 hour so JavaScript SDK accepts disableCache
argument. It's a boolean
and if provided the response will NOT be cached.
Filters argument accept the following options:
- action.
enum
. All provided actions are described here. - page.
number
. The number of the page. - limit.
number
. Determines how many items per page there will be.
const userId = "userId";
const filters = {
action: 'like',
page: 2,
limit: 1,
};
const disableCache = true;
sdk.activity
.getForUser(userId, filters, disableCache)
.then((responseObject) => {
// do something with responseObject
})
.catch((error) => {
// handle error
});
Example result
meta: {
pagination: {
currentPage: 2,
itemsPerPage: 1,
totalItems: 257697,
numberOfPages: 12885
}
},
data: [
{
id: "c83b127a-3238-4b1d-8f6d-1db2851fafe0",
profileId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
action: "like",
context: {
content: {
id: "123131",
type: "article",
label: "asd123"
},
tags: [
{
id: "football",
type: "team",
source: "fb:t:8102"
},
{
id: "football",
type: "competition",
source: "fb:c:3"
},
{
id: "football",
type: "player",
source: "fb:p:43400"
}
],
campaign: {
id: "your-campaign-id-here",
label: "Carlsberg 2022"
}
},
points: 10
}
]
Updated 11 months ago