Grouping
Patterns of data
Scenario
It can be a useful requirement to group or aggregate visitor data by a label against a predefined set of patterns, the example below is for IP ranges by groups but this could also be useful for:
- Activities
- Email Domain
- Entry to the Site
- ...
Question
This example is grouping or aggregating a users data for comparison to a data table, but can you think of other related uses?
Example Event Script
Example Adv. Event
// Generated by Discover Event Manager
// NOTE: Do not change event name
function CUST$E_GROUP__634916041725704920() {
if ($P["TL.REMOTE_ADDR"].patternFound()) {
var group = "Public";
var IP = $P["TL.REMOTE_ADDR"].firstValue();
// Dictionary of IP patterns and their corresponding groups
var ipPatterns = {
"((206.108.(41|40).\\d{1,3})|(199.16.140.(6[4-9]|7[0-9]))|(199.187.152.(3[2-9]|4[0-7]))|(208.240.243.170)|(199.16.136.(20[2-9]))|(199.16.140.(2[4-9]|3[0-1])))": "Group-A",
"216.34.61.\\d{1,3}|64.41.181.\\d{1,3}|64.14.(28|29).(3[3-9]|[4-5][0-9])|216.205.83.([1-5][0-9]|6[0-2])|180.179.206.(104|163|90)": "Group-B",
"208.83.(10[4-9]|11[0-1]).\\d{1,3}": "Group-C",
"67.221.(34.15(0|1|3|7)|33.4)": "Group-D",
"209.200.(12[8-9]|1[3-8][0-9]||19[0-1]).\\d{1,3}": "Group-E",
// Add other patterns here...
};
// Iterate through the dictionary and check for matches
for (var pattern in ipPatterns) {
if (IP.match(pattern)) {
group = ipPatterns[pattern];
break;
}
}
// Set fact for Report Group: No Dimension Report Group
$F.setFact("CUST.F_E_GROUP__634916041725704920", group);
}
}
Tips
- As with all advanced events, it is best practice to create the event using the UI as much as possible and only converting to Advanced Mode when additional scripting is required. This is particularly useful when several conditions are required.
- The function name and number/id is generated at creation time and should not be modified. Any modification without a full event re-creation will have undesired results.
The group results stores the compared group name value from the table the data matched.