CMS Development

piersg
Key Advisor

Tracking URL is conflicting with HubL request.path

SOLVE

I have a directory with content being generated from a HubDB. It uses query parameters for filtering based on categories etc.

 

Here's the specific code that is conflicted by the tracking url parameters. This is supposed to show a small hero section if there is no query parameter in the URL, or no header and a link back to the Marketplace home if there is one (i.e. if filtering has been applied).

{% if request.path_and_query is string_containing "?" %}
  <div class="row mt-80">
    <div class="column">
      <div class="int-back-wrap"><small><strong><a href="/products/marketplace"><span class="int-left-arrow"></span>Back to Marketplace home</a></strong></small></div>
    </div>
  </div>
{% else %}
  {% module "hero_section" path="/Bachoo_theme_Mews_Systems/modules/Small Section Marketplace", label="Small Section Marketplace" no_wrapper=true %}
{% endif %}

When I console log the path_and_query I get this, which I think are Hubspot tracking URL parameters

/products/marketplace?hsSkipCache=[true]&hs_ungate__cos_renderer_combine_all_css_disable=[true]&hsNotRandom=[true]

 

Here's the current web page where this is happening: https://www.mews.com/products/marketplace

Here's a staging link of the same page, where everything is working as it should:

http://www-mews-com.sandbox.hs-sites.com/products/marketplace

 

 

0 Upvotes
1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Tracking URL is conflicting with HubL request.path

SOLVE

@piersg it might be a bit easier to manage if you were to set a variable and change that variable with the multiple if statements instead of having a ton of "or"s in a single if statement:

{% set isFilteredView = false %}
{% if request.query_dict.category %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.another %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.anotherone %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.etcetc %}
  {% set isFilteredView = true %}
{% endif %}

that way you could have all your logic away from your template/markup.

Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

5 Replies 5
stefen
Key Advisor | Partner
Key Advisor | Partner

Tracking URL is conflicting with HubL request.path

SOLVE

@piersg looking for a "?" is a bit too broad of a search especially since if you use any type of CTA to get to that page or social media link it will always have query parameters. What you could instead look for are your specific query parameters like so:

{% if request.query_dict.category or request.query_dict.contact_free %}
 this is a filtered hubdb result
{% endif %}
Stefen Phelps, Community Champion, Kelp Web Developer
piersg
Key Advisor

Tracking URL is conflicting with HubL request.path

SOLVE

Good point, thanks @stefen. There are quite a few to check for but hey-ho, sometimes that's just what you've got to do.

stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Tracking URL is conflicting with HubL request.path

SOLVE

@piersg it might be a bit easier to manage if you were to set a variable and change that variable with the multiple if statements instead of having a ton of "or"s in a single if statement:

{% set isFilteredView = false %}
{% if request.query_dict.category %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.another %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.anotherone %}
  {% set isFilteredView = true %}
{% endif %}
{% if request.query_dict.etcetc %}
  {% set isFilteredView = true %}
{% endif %}

that way you could have all your logic away from your template/markup.

Stefen Phelps, Community Champion, Kelp Web Developer
piersg
Key Advisor

Tracking URL is conflicting with HubL request.path

SOLVE

I ended up using your second option (but as one long or so it's on fewer lines), as I check for the query a few times in the template.

 

{% set isFilteredView = false %}
{% if request.query_dict.category or request.query_dict.contact_free or request.query_dict.show or request.query_dict.status or request.query_dict.most_used or request.query_dict.plug_and_play %}
  {% set isFilteredView = true %}
{% endif %}

Could equally do it with else if:

{% set isFilteredView = false %}
{% if request.query_dict.category %}
  {% set isFilteredView = true %}
{% elif request.query_dict.another %}
  {% set isFilteredView = true %}
{% elif request.query_dict.anotherone %}
  {% set isFilteredView = true %}
{% elif request.query_dict.etcetc %}
  {% set isFilteredView = true %}
{% endif %}

Thanks for your help @stefen 

piersg
Key Advisor

Tracking URL is conflicting with HubL request.path

SOLVE

Another good option, thanks @stefen.

 

I've implemented the first one for now and I'm double checking that it works (hubspot is being very slow in actually pulling through the template update).

 

I'll test the second one in staging as well, and then replace after confirming it works 🙂