Hi Ben! I think that you are close, but you have the segment conditions inverted. You'd want the highest most condition to be the `booleanCondition`. (Does the user, or does the user not meet this condition.)
Inside of that is where you'd use the `pastEventCondition`. Below is an example from a project I am working on. Hopefully this will help you get a better sense of the structure. ``` > "condition": { > "parameterValues": { > "subConditions": [ > { > "type": "pastEventCondition", > "parameterValues": { > "numberOfDays": 10, > "minimumEventCount": 1, > "eventCondition": { > "type": "eventPropertyCondition", > "parameterValues" : { > "propertyName" : > "target.properties.pageInfo.taxonomies.category", > "comparisonOperator" : "contains", > "propertyValue" : "arrangement" > } > } > } > } > ], > "operator": "and" > }, > "type": "booleanCondition" > } ``` On Wed, Apr 29, 2020 at 9:04 AM Ben Schiefer <benschie...@gmail.com> wrote: > Hello, and thanks for Unomi, its awesome. > > I've been wading through the unomi code for the last few days trying to > figure out how to properly use the pastEventCondition type in a segment. I > am able to register the segment just fine and have it execute against > elastic correctly, but when the "setEventOccurenceCountAction" picks up the > Auto Generated rule to try to increment the count of this event on the > "pastEvents" map on a profile, the action fails with an error because the > eventCondition is null on this line ( > https://github.com/apache/unomi/blob/ea1b788ec82b2ad8e404236e21d974a11e68429a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/SetEventOccurenceCountAction.java#L53 > ) > > Here is my segment definition > ``` > { > "metadata": { > "id": "10viewstoday", > "name": "At least 10 views in last day", > "scope": "systemscope", > "description": "Profile with at least 10 views in last 1 day", > "readOnly": true, > "enabled": true > }, > "condition": { > "type": "pastEventCondition", > "parameterValues": { > "eventCondition": { > "type": "booleanCondition", > "parameterValues": { > "operator": "and", > "subConditions": [ > { > "type": "eventTypeCondition", > "parameterValues": { > "eventTypeId": "view" > } > }, > { > "type": "eventPropertyCondition", > "parameterValues": { > "propertyName": "target.itemType", > "propertyValue": "flow", > "comparisonOperator": "equals" > } > } > ] > } > }, > "numberOfDays": 1, > "minimumEventCount": 10 > } > } > } > ``` > > > Here is the auto generated rule for that segment > ``` > { > "_index": "context", > "_type": "rule", > "_id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a", > "_version": 1, > "_score": 1, > "_source": { > "itemId": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a", > "itemType": "rule", > "condition": { > "parameterValues": { > "eventTypeId": "view" > }, > "type": "eventTypeCondition" > }, > "actions": [ > { > "parameterValues": { > "pastEventCondition": { > "parameterValues": { > "operator": "and", > "subConditions": [ > { > "parameterValues": { > "eventTypeId": "view" > }, > "type": "eventTypeCondition" > }, > { > "parameterValues": { > "propertyName": "target.itemType", > "propertyValue": "flow", > "comparisonOperator": "equals" > }, > "type": "eventPropertyCondition" > } > ], > "generatedPropertyKey": > "eventTriggered62e083f24cb05e41a2c046c5c4be2086" > }, > "type": "booleanCondition" > } > }, > "type": "setEventOccurenceCountAction" > } > ], > "linkedItems": [ > "10viewstoday" > ], > "raiseEventOnlyOnceForProfile": false, > "raiseEventOnlyOnceForSession": false, > "priority": 0, > "metadata": { > "id": "eventTriggered47062c82c5a374d5ab2d2178b9cba16a", > "name": "Auto generated rule for At least 10 views in last > day", > "description": "", > "scope": "systemscope", > "tags": [], > "systemTags": [], > "enabled": true, > "missingPlugins": false, > "hidden": true, > "readOnly": false > } > } > } > ``` > > > > Any help you could provide would be greatly appreciated. I'm not sure if > i'm using the pastEventCondition improperly in my segment, or if there is a > bug when generating the rule in the segment service ( > https://github.com/apache/unomi/blob/27859f99d3b33640b6e6cf62f9b878e56994039d/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java#L728 > ) > > > Thanks in advance, > Ben > -- *Gary Thayer* • Lead Web Engineer, 10up <http://10up.com/>