Share Your Work

djbokka
Member | Diamond Partner
Member | Diamond Partner

If statement to check list/contact membership status

We were trying to use smart content to display "promotions" for gated content if a user hadn't yet downloaded the content. While possible with smart content, this proved to be challenging and confusing. We had to create lists for users that had not downloaded the content, then create smart rules based on those list memberships to load the next available promo, etc. It just wasn't very intuitive or easy to maintain. (Not to mention, Hubspot's smart content rules seem to be an anti-pattern for traditional switch statements - putting the default case at the beginning rather than the end.)

 

I thought I'd share our solution in the event someone else is looking for something similar:

 

  • We created a HubDB table that holds the promo information (image, CTA, content, sort order) and added a list_id column. This holds the list ID for the contacts who have downloaded this promo content. This keeps our lists clean and intuitive.
  • Next, we created a module with a single custom field to select the HubDB table. It then checks the contact's list memberships and displays the promo if they're not on the list.
<!--  Try to retrieve list memberships from contact information -->
{% set memberships = request_contact.list_memberships %}

<!--  Retrieve our list of promos from HubDB table -->
{% set promos = hubdb_table_rows(module.hubdbtable_field,"orderBy=sort_order") %}

<!--  Set flag for displayed promo -->
{% set promo_displayed = false %}

{% for promo in promos %}

  {% if not promo_displayed %}

    <!-- check contact's memberships and display this promo if they're not already on the list -->
    {% unless promo.list_id in memberships %}

      <a href="{{promo.destination_url}}"><img src="{{promo.image.url}}" alt="{{promo.title}}" width="{{promo.image.width}}" style="width: {{promo.image.width}}px;"></a>
      
      {{cta(promo.cta_id)}}

      <!-- Set our flag to break the loop -->
      {% set promo_displayed = true %}

    {% endunless %}

  {% endif %}

{% endfor %}

Now, to add a new promo, we just add a new row to the HubDB table. If the user has downloaded content from a promo, they'll automatically see the next promo in the list.

This is working well for us. Hope it helps!

0 Upvotes
1 Reply 1
jennysowyrda
Community Manager
Community Manager

If statement to check list/contact membership status

Thanks for sharing @djbokka!

0 Upvotes