Back

This article describes the tally attribute and how to use it in the Customer Data Hub.

In this article:

Table of Contents Placeholder

How It Works

Before you begin, familiarize yourself with the following:

The tally attribute maintains a collection of key/value pairs, called entries, that count the occurrences of named items across many events.

  • Key represents the name of the item that occurred, for example the value of the product_category attribute "Shoes".
  • Value represents the number of times it occurred

For example, to keep track of the product categories that a visitor purchases from, use a tally named "Product Category Purchases" and enrich it with the names of product categories found in the event attribute product_category when purchase events occur. Over time the tally will provide valuable information about the visitor's buying habits.

Tally Favorite

By default, each tally attribute generates a corresponding string attribute that automatically captures the name of the tally entry with the highest value. This string attribute has the same name as the tally, but with the word "(favorite)" appended. For example, a tally named "Product Categories Purchased" would also have a string attribute named "Product Categories Purchased (Favorite)".

Scope

The tally attribute is available in the following scopes: Visit and Visitor.

Screenshot 2019-11-11 at 1.26.28 PM.png

Example

The following table illustrates the example of a tally named "Product Category Purchased", which counts the number of times each product category was purchased from. This tally automatically populates a string attribute with the name of the entry containing the highest value.

Tally Attribute: "Product Category Purchased"
Tally Key Tally Value
"Shoes" 1
"Pants" 3
"Shirts" 7
"Shorts" 2
String Attribute: "Product Category Purchased (Favorite)" "Shirts"

Tally Attribute Enrichments

Increment Tally

Increment a number within a tally based on the value of another attribute. For example, to track the number of times each product category is viewed, use a tally named "Product Category Viewed" and enrich it with the product_category attribute. The values of product_category become entries in the tally.

Attribute Name: "Product Category Viewed"

Starting Value {"Shoes": 7, "Pants": 1, "Shirts": 3}
Enriched With product_category:"Shoes"
Resulting Value {"Shoes": 8, "Pants": 1, "Shirts": 3}

Increment Tally Value

Increment a tally entry based on a custom name with a custom value or another attribute value. For example, use a tally named "Product Category Searched" and enrich it with a hard-coded value of "Did Not Search" when a search has not occured (a condition likely based on a boolean attribute that keeps track of searches). Since the name "Did Not Search" would not naturally occur in a product_category attribute, this enrichment is used to add the custom entry.

Attribute Name: "Product Category Searched"

Starting Value {"Shoes": 7, "Pants": 1, "Shirts": 3}
Enriched With Custom Key: "Did Not Search"
Custom Increment: 1
Resulting Value {"Did Not Search": 1, "Shoes": 7, "Pants": 1, "Shirts": 3}

Increment Tally by Tally

Increment the values in a tally by the values found in another tally.

Attribute Name: "Product Category Purchased (Lifetime)"

Starting Value {"Shoes": 7, "Pants": 1, "Shirts": 3}
Enriched With {"Shoes": 1, "Shirts": 2, "Dresses": 1}
Resulting Value {"Shoes": 8, "Pants": 1, "Shirts": 5, "Dresses": 1}

Increment Tally by Set of Strings

Increment the entries in a tally based on the entries in a set of strings. For example, use a tally named "Product Category Searched (Lifetime)" to track the product categories searched per visit, and enrich it with a set of strings named "Product Categories Searched (Visit)" at the end of each visit.

Attribute Name: "Product Category Searched (Lifetime)"

Starting Value {"Shoes": 7, "Pants": 1, "Shirts": 3}
Enriched With Product Categories Search (Visit):{"Shoes", "Pants", "Hats"}
Resulting Value ["Shoes": 8, "Pants": 2, "Shirts": 3, "Hats": 1}

Set Rolling Average Based on Timeline

The rolling average is the arithmetic mean of numerical values captured over time. These values come from number and tally attributes that are all collected as entries in a Timeline. The timeline's expiration determines which entries can be factored into the final average. If there is no expiration date, it is a simple average solution.

For a detailed example, see Number/Tally Enrichment: Set Rolling Average Based on Timeline.

Attribute Name: "Average Product Category Purchase Amounts"

Starting Value {}
Enriched With

Timeline entry: {"Shoes": 150.00, "Pants": 75.00, "Shirts": 30.00}
Timeline entry: {"Pants": 75.00, "Shirts": 42.00}
Timeline entry: {"Shoes": 110.00, "Shirts": 18.00 "Hats": 25.00}

Resulting Value {"Shoes": 130.00, "Pants": 75.00, "Shirts": 30.00, "Hats": 25.00}

Set Rolling Sum Based on Timeline

A rolling sum is the aggregate of numerical values in a number or tally, attributes that are captured as entries in a timeline. The Timeline's expiration determines which entries can be factored in during the aggregation. For detailed information, see Number/Tally Enrichment: Set Rolling Sum Based on Timeline.

Attribute Name: "Average Product Category Purchase Amounts"

Starting Value {}
Enriched With

Timeline entry: {"Shoes": 150.00, "Pants": 75.00, "Shirts": 30.00}
Timeline entry: {"Pants": 75.00, "Shirts": 42.00}
Timeline entry: {"Shoes": 110.00, "Shirts": 18.00 "Hats": 25.00}

Resulting Value {"Shoes": 260.00, "Pants": 150.00, "Shirts": 90.00, "Hats": 25.00}

Set Tally by Corresponding Arrays

Set the tally to the values defined in two corresponding arrays. For example, use a tally named "Product Category Quantity Purchased" to capture the quantity of products purchased and enrich it with the two arrays product_category and product_quantity when a purchase event occurs.

Attribute Name: "Product Category Quantity Purchased"

Starting Value  {}
Enriched With

product_category: ["Shoes", "Pants", "Shirts"]

product_quantity: [1, 1, 3]

Resulting Value {"Shoes": 1, "Pants": 1, "Shirts": 3}

Remove Tally

Remove tally based on a set of conditions.

The remove tally enrichment can be used to reset a tally. For example, if you have been tracking visitor's product category searches, you might clear that tally once an order is placed.

Attribute Name: reset tally to zero

Starting Value {"Shoes": 1, "Pants": 3}
Enriched With Purchase event occurs
Resulting Value {}

Remove an Entry in a Tally

Remove an entry in a tally based on a set of conditions. For example, use a tally named "Product Category Searched" to track a visitors product searches (and potential purchases) then use this enrichment to remove the tally entries that match items in a purchase.

Attribute Name: "Product Category Searched (Not Purchased)"

Starting Value {"Shoes": 7, "Pants": 1, "Shirts": 3, "Jeans": 10}
Enriched With product_catgory : "Shoes"
Resulting Value ["Pants": 1, "Shirts": 3, "Jeans": 10]

Increment by 1 for Each Item in an Array

Increment by one (1) for each item in an array. For example, use a tally named "Product Category Purchased" and enrich it with the array attribute product_category when a purchase event occurs.

Attribute Name: "Product Category Purchased"

Starting Value {"Shoes": 1, "Pants": 1, "Shirts": 3}
Enriched With product_category : ["Pants", "Ties"]
Resulting Value {"Shoes": 1, "Pants": 2, "Shirts": 3, "Ties": 1]