Filter Subscribers by Tag Count Workflow for Drip
Perform automation actions based on a subscriber's number of tags
This workflow calculates the total number of tags for a subscriber and then provides a decision which you can use to filter your subscribers based on total tag count.
1 Workflow Triggers
This workflow has no pre-configured triggers. You can add triggers inside the workflow after installing it, add subscribers to the workflow from other automations, or add subscribers manually with a bulk operation.
2 Calculation of Total Tags
A decision needs to be based on a property of a subscriber, so the total number of tags is calculated via a Liquid statement and stored in the 'total_tags' custom field. More technical details on the Liquid statement are available here.
3 Tag Count Decision
A decision is used to compare the total tag number to another value.
4 Filter Actions
The paths following the decision are left blank in this workflow for you to fill in with your specific automation actions.
Steps to Install and Customize this Workflow
- Sign up using the form above to get the workflow installation link
- Install the workflow into your Drip account using the provided link
- Update the decision to use the desired comparison (e.g. equals, greater than, etc) and value
- Add the desired actions on either or both of the post-decision paths
- Optionally add any desired triggers for the workflow
- Start the workflow
Technical Details About Calculating the Tag Count Using Liquid
A subscriber's tags can be referenced as a Liquid array using the following syntax:
To get the size of that array you would normally just send that array into the size filter like this:
The reason that the Liquid statement used in this workflow is more complicated is because Drip has a special way of treating capitalized tags. If you apply a tag to a subscriber that includes capitalized letters, Drip automatically adds a non-capitalized version of that tag.
Example: If the tag 'Customer' is applied to a subscriber, 'customer' is also applied to the subscriber. This doesn't appear in the subscriber section of the Drip interface, but if you access the subscriber tags array via Liquid, you would find both 'Customer' and 'customer'.
This tag dupllication means that the following filter will not give us an accurate count of unique tags:
To further complicate matters a bit, the duplicate tag is only added when a capitalized version of the tag is added. So if you were to add 'customer' instead of 'Customer', the subscriber would only have the tag 'customer'.
What this ultimately means in terms of getting the subscriber account is we have to filter to get only the unique tags before getting the total count.
Liquid does have a 'uniq' filter that can be applied to an array, but that filter is case sensitive. This means that only using the 'uniq' filter on the subscriber tags array would still leave us counting both 'Customer' and 'customer' for instance.
The solution is to take the subscriber tags array and make all of the entries lowercase so that we can successfully filter by uniques and then count only those unique values.
Converting the subscriber tags array to lowercase is a 3 step process:
- Create a single string with all of the subscriber.tag strings joined by a unique identifier (in this case: **,**)
- Take the tag string and run it through the downcase filter to make sure everything is lowercase
- Convert the lowercase tag string back into an array by using the split pattern with the same pattern as before
Now that we have an array of all lowercase subscriber tags, we can run it through the uniq filter to remove duplicates and through the size filter to get the total tag count. The final Liquid statement looks like this: