Capture User Filters Then Write Back To MongoDB
Use case: Capturing what the end-user has selected to filter. Then writing back the filtered selection to the app mongodb for further analysis of customer dashboard interaction.
Instructions: Add the code below as a dashboard script.
Notes: Current script will write to the application mongodb leveraging the custom_data api. Update the ajax call to post data to another source.
prism.on('dashboardloaded', function () {
prism.activeDashboard.$$events.filterschanged.handlers.push(handleEventsChange); console.log(prism.activeDashboard)})
function handleEventsChange(sender, event) {
var length = event.items.length;
console.log(event)
var username = prism.user.userName; event.items.forEach(curJAQL => {
if (curJAQL.jaql.filter != null && curJAQL.jaql.filter.exclude != null) {
var payload = {
type: 'user-filter-exclude',
user: username,
dimension: curJAQL.jaql.dim,
filterValues: curJAQL.jaql.filter.exclude.members
} console.log(payload) $.ajax({
url: '/api/v1/custom_data',
method: 'POST',
contentType: "application/json",
data: JSON.stringify(payload)
})
} else if (curJAQL.jaql.filter.explicit===true){
var payload = {
type:'user-filter-include',
user: username,
dimension: curJAQL.jaql.dim,
filterValues: curJAQL.jaql.filter.members
} console.log(payload) $.ajax({
url: '/api/v1/custom_data',
method: 'POST',
contentType: "application/json",
data: JSON.stringify(payload)
}) }
});}
Updated 03-02-2023
intapiuser
Admin
Joined December 15, 2022