Intelligence object

Intelligence object

TODO:

  • explain that constructor is mostly for filtering, while calling intelligenceObject.addUserProperty(..) or intelligenceObject.addUserProperties(..) is for adding.
  • addUserProperty/addEvent/addEventProperty/addSegment, as well as addUserProperties, etc.
  • adding via variables, as well as directly via Utils.getProperty({table: "users", property: "u_col_initial_campaign_source"}) or addUserProperty({table: "users", property: "u_col_initial_campaign_source"}) / table: "events"
  • intelligenceObject.addCalculation({type: "count-event", event: event.name, name: ${event.name} actions in first ${time.label}, filter: {equalsOrLessThanSeconds: time.seconds}});
  • Custom SQL property / goal

Below is how the constructor of an intelligence object looks like:

new Intelligence({
goal: { // Or use intelligence.setGoal({...}) with same object. Same use {data: ...} to set raw goal object.
event: "paid",
times: 1
},
userProperties: true, // Add all user properties, default to true if param is undefined
userProperties: (userProperty) => { return userProperty.name.includes('device') }, // Adds only if evaluates to true
- Where userProperty looks like:
{
type: 'number', // Can be 'number', 'text', 'timestamp', 'boolean'
custom: false, // If true, its a end-user defined property
name: 'initial_country', // Or whatever custom property was set in tracking
unbiased: false, // If custom property, true means this is a unbiased property that was set at user creation time
category: 'device',
subCategory: 'screen'
}
eventProperties: true, // Add all event properties, default to only custom set event properties if param is undefined
eventProperties: (eventProperty) => { return eventProperty.name.includes('device') }, // Adds only if evaluates to true
- Where eventProperty looks like:
{
event: 'event_xyz', // Name of event
eventCategory: 'pageview', // Category of event. Default available in addition to any custom ones: 'auto' and 'event'
type: 'number', // Can be 'number', 'text', 'timestamp', 'boolean'
custom: false, // If true, its a end-user defined property
name: 'initial_country', // Or whatever custom property was set in tracking
category: 'device',
subCategory: 'screen'
}
events: true, // Adds all possible events, default to only 'event' and 'auto' category events if param is undefined
events: (event) => { return event.name === 'signed_up' }, // Adds only if evaluates to true
- Where eventProperty looks like:
{
name: 'event_xyz', // Name of event
category: 'pageview' // Category of event. Default available in addition to any custom ones: 'auto' and 'event'
}
calculations: true, // Add all user calculations, default to true if param is undefined
calculations: ['boolean', 'text'], // Adds only 'boolean' and 'text' user properties. All options: ['number', 'text', 'timestamp', 'boolean']
calculations: (property) => { return property.name.includes('device') }, // Adds only if evaluates to true
segments: true, // Adds all possible segments, default to true if param is undefined
segments: (segment) => { return segment.name.includes('mobile') }, // Adds only if evaluates to true
});

Intelligence goals

  • new Intelligence() helpers:

    • Note: by default no-goal is used. Only once setGoal is called, we have a goal set.
    • Note: to use raw custom things, look in console "generalIntelligenceStore: ", and use that as {data: ...}.
    • Others: intelligence.addUserProperties(p => (p.name === 'created_at')); intelligence.addEventProperties(p => (p.name === 'created_at'));
    • Each returns this, so that we can chain commands.
note

the events, per, dateRanges and other construction options can only be used once in the constructor. E.g. setting later reportObject.events = ['other_event'] will not work; we need to use the setters like reportObject.setEvents(..) (overwrite) reportObject.addEvents(..) (adds). All other props have overwritting setters: reportObject.setTimeUnit(..), reportObject.setDateRanges(..)

  • Also note that methods can be chained: new Report().setEvents().setTimeUnit();

General

PluginData.get('clustering', {data: '...', userMomentBaseProperty: 'identified_at'})
  • new Intelligence() examples for:
    • setUserFilter(...) / new Intelligence({userFilter: ...})
      • Explain that index: 0/1/2/3 is needed for each object in "queries" and "conjunctions", if has >= 1 conjunctions. Also that user filter can be gotten probably easiest by making one in report "user filter", then debug that.
        • Also that "steps" is necessary!
    • Explain that the user filter can best be gotten from
      on a report that has "user filter" we want, just the IDs should be replaced?
    • Note that there is no way to set Segment filter, as this works by id, and doesn't make sense; we can always use useFilter to reach the same.
    • "When you run a plugin with hyper-parameters, the metrics and scores for different parameter combinations can be found in the browser console."

Recipes

Adding user/event properties

  • Custom SQL properties (also add helper for this?)

  • In constructor via filter

  • Utils.getUserProperties(); // Returns all user properties, can be used in Intelligence.addUserProperties();

  • Utils.getEventProperties(); // Returns all event properties, can be used in Intelligence.addEventProperties();

Friendly user-filters/user-segments

Options:

  • Utils.createUserFilter(..., ..., {skipSegmentFilter: true, skipUserFilter: true}) and Utils.userFriendlyFilter(..., ..., {skipSegmentFilter: true, skipUserFilter: true})

Or:

const friendlySegments = clusters.data.segments.map((segment, idx) => ({human: Utils.userFriendlyFilter(segment, clusters), size: clusters.data.clusters.clusters[idx].size, conv: clusters.data.clusters.clusters[idx].conversion_rate})); const filterSegments = clusters.data.segments.map(segment => Utils.createUserFilter(segment, clusters));

friendlySegments.forEach((segment, idx) => { Notifications.add({ id: ObjectHash(segment.human), title: ${(segment.conv*100).toFixed(2)}% 1-week retention. ${segment.size.toLocaleString()} users, message: Segment Properties: ${segment.human}, status: "info", score: 1.0 }); });

Event count

Utils.getEvents().forEach(event => {
if (event.category != "pageview") {
intelligence.addCalculation({type: "count-event", event: event.name, name: `Did ${event.name}`});
}
});

User filter - Has event

- To set custom user filter (e.g. "had event X"):
intelligence.data.userFilter = {
"queries": [
{
"event": questions.checkout.value,
"property": {
"event": questions.checkout.value,
"type": "boolean",
"human": "Has this event"
},
"operator": {
"value": "IS NOT NULL",
"type": "boolean"
},
"valueType": "hasThis",
"valid": true,
"queryType": "event"
}
],
"conjunctions": []
};