Cross Domain tracking not working for HubL Markup and Membership Content

SOLVE
Highlighted
Regular Contributor

We deployed the private content and membership manager on our website, built on the HubSpot CMS. We ran into an issue where the login parameters are not working when checked in HubL. Specifically, I wanted to adjust menu items based on if the user is logged in or not. Below is the code.

 

 <ul>
      <li>{% if request_contact.is_logged_in == true %}Hi, {{ contact.firstname }}{% else %}<a href="http://www.domain.com/_hcms/mem/login" rel=" noopener">Member Login</a>{% endif %}</li>
      {% if request_contact.is_logged_in %}<li><a href="https://www.domain.com/_hcms/mem/reset/request">Reset Password</a></li>{% endif %}
      <li><a href="https://www.domain.com/profile">Community Profile</a></li>
      {% if request_contact.is_logged_in %}<li><a href="http://www.domain.com/profile" rel=" noopener">Portal</a></li>
      <li><a href="https://www.domain.com/advisory/schedule">Priority Scheduling</a></li>{% endif %}
      <li><a href="https://www.domain.com/search">Site Search</a></li>
      {% if request_contact.is_logged_in %}<li><a href="http://www.domain.com/_hcms/mem/logout ">Sign Out</a></li>{% endif %}
 </ul>

 

On the main domain (www.domain.com), the HubL works as expected, substituting "Hi, {{First Name}}" for "Member Login" and adding in the extra links. But on our blog subdomain, (blog.domain.com), these if statements always return false, even when the user has logged in. I'm assuming this has to do with the way cookies are cached and checked when a user logs in, but it seems odd that it does not work across domains, considering the password protection is only based on lists and can be applied across domains. Is this intended behavior, and is there a workaround for this?

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Regular Contributor | Diamond Partner

Here's the reply I got from a Hubspot dev on this issue:

 

"This is currently by design because we don’t know if you want to share the login across domains. We default to the more secure option. We may expose this as an option in the future."

 

So, unfortunately, at this time the request_contact.list_membership work around is all that can be done.

 

Alyssa Wilie
Web Developer

LyntonWeb

9 Replies 9
Community Manager

Hey @mgoswick 

 

 I will tag a few of our experts Emoticono feliz     

 

Hey @amwilie @DanielSanchez @dennis_e  could you please share your knowledge with @mgoswick ?

 

Thank you,

Sharon 

Reply
0 Upvotes
Regular Advisor | Platinum Partner

@mgoswick , i have never tried this.  I would have to build it out and test.  Will give it a shot and get back to you in the next day or so

Maybe someone will be quicker than i Smiley Happy

dennis
Regular Contributor | Diamond Partner

From my understaing of Hubspot Membership the logged in state would only work on pages set to Private. Are there pages on your main domain not set to private where your is_logged_in is working? If not, a workaround you could use is just checking if the user is in the list being used for membership.

 

{% if "XXXX" in request_contact.list_memberships %}
  <!-- logged in html -->
{% else %}
  <!-- logged out html -->
{% endif %}

XXXX being the number ID of the list.

Alyssa Wilie
Web Developer
LyntonWeb

Regular Contributor

Yes, it works on all pages on the main domain. I have a menu item that is only visible if members are logged in, and it works on all pages, which is why I was surprised it did not work across sub-domains. With that said, the list membership might be a good workaround, since private membership is tied to a particular list anyways and all our membership is tied to a single static list.

 

Either way, it would be good to know if list membership is meant to not be cross-domain, or if there is a way to make those tokens cross-domain.

 

Thanks @amwilie and all helping with this.

Regular Contributor | Diamond Partner

That is strange then why it wouldn't be working on the subdomain as the hubspotutk cookie does use a wildcard domain so as to encompass even subdomains. Do you have any landing/website pages on a subdomain where the variable won't work? Wondering if it's just an issue with blogs or the subdomain as a whole.

Reply
0 Upvotes
Regular Contributor

It's definitely the subdomain, as we use the blog tool to host press releases on domain.com/press-release and the menu works correctly with showing and hiding the menu items.

Reply
0 Upvotes
Regular Contributor | Diamond Partner

Here's the reply I got from a Hubspot dev on this issue:

 

"This is currently by design because we don’t know if you want to share the login across domains. We default to the more secure option. We may expose this as an option in the future."

 

So, unfortunately, at this time the request_contact.list_membership work around is all that can be done.

 

Alyssa Wilie
Web Developer

LyntonWeb

Regular Contributor

That both makes sense and is unfortunate. It's problematic as the workaround would apply styling even when they are not logged in, as long as the browser was cached as that person (an email on any submission form). In practice, the workaround should not have a large impact on the UX in this particular case, but would in cases where you want to display non-confidential, sensitive information (like subscription level) after someone has logged in.

 

Regardless, thanks for all the help with this!

Reply
0 Upvotes
Top Contributor | Platinum Partner

Hi Mgoswick,

 

I send an option that is not exactly for logged in users, but that allows you to customize content based on contact property.

 

First, u need create this property:

1-contact-prop-create.PNG

 

After, you should create one rule CSS to show onde menu and hide other. Look my example:

 

HTML

<div class="menu-test default-{{ contact.test_validation }}">{% menu id="{{ module.menu_field }}" %}</div>
<div class="menu-test version2-{{ contact.test_validation }}">{% menu id="{{ module.menu_logged }}" %}</div>

CSS:

.menu-test{
  display:none;
}

.default-default{
 display:block;
}

.version2-Version2 {
  display:block;
}

And the preview shows only the menu based on the contact property.

only-one-menu.PNG

The property value, I set as a CSS class that applies a display: block, to a contact that defaults to display: none.

 

Obs: This property that I created below is for example only. In this case you can rely on a property set after a contact completes a form, or other HubSpot action.

 

Hope this helps.