Anchor Link Scroll Effect Using a Hubspot CTA

SOLVE
Top Contributor

Hi, Im trying to add a link to a cta button so that when clicked the page scrolls. Unfortunatly in the cta edit I need to add a valid URL protocol to the link field. I can only add the whole url which forces the page to reload to the anchor point rather than allowing me to just add #anchorname into the link field.

Is there any way that I can use hubspot cta buttons to call a #anchorname only?

1 Accepted solution

Accepted Solutions
Regular Advisor

Is there a reason your trying to use a CTA for this  vs a regular HTML anchor tag? CTA's are used to track views, clicks and submissions for converstion analytics. I don't see a whole lot of value using a CTA over a standard HTML anchor link for in-page navigation.

14 Replies 14
Regular Advisor

Is there a reason your trying to use a CTA for this  vs a regular HTML anchor tag? CTA's are used to track views, clicks and submissions for converstion analytics. I don't see a whole lot of value using a CTA over a standard HTML anchor link for in-page navigation.

HubSpot Employee

@ndwilliams3 I would completely agree! Unless you had a specific reason for doing so, I wouldn't think that a page navigation would need to be built with CTAs. @Woodsy I don't believe that you can use relative URLs in the CTA tool but you can follow along with the instructions in this Academy article (https://knowledge.hubspot.com/articles/kcs_article/cta/can-i-use-an-anchor-id-in-the-url-link-of-a-h...) to add an anchor ID to the end of an absolute URL. 

Highlighted
Occasional Contributor

What about the case of a single page application or a long single-page site with scrolling navigation? It also seems that it's not possible to handle the click of a CTA with a script in a way that allows the tracking functionality to be passed. It's severely limiting that CTA buttons can only be used to navigate to a different page. It is possible to use the hash navigation, but then you are still reloading the page and have the odd "jump" effect. Having the ability to send the tracking via a script API and handle the click, or at least the ability to use a relative URL would be incredibly useful in terms of flexibility.

Regular Contributor

I'm using a CTA button (from image file) as opposed to a link. So yes, there is still a reason to find another solution for this issue.

Reply
0 Upvotes
Occasional Contributor

This would be an awesome addition.

 

We just launched a landing page with a form at the very bottom, so we used CTAs throughout the page to bring people down to the form instead of linking to a completely new page.

 

Some of you asked why you'd do this? Well, here were a few of our motivators:

  • Saves on load time. They've already loaded the page they need to be on.
  • Track CTA performance. We can see what section triggered someone to click.
  • Run tests. Based on a combination of CTA, section order, copy, imagery, and audience — we can optimize each for the best conversions.

With the current implementation of CTA's anchor URL behavior and limitations, it creates a rough user experience as the page reloads, the screen flashes, and then they're teleported down to the form.

Regular Contributor

@ringo-at-wt Well said and so true! Hubspot please consider implementing current page Anchor CTAs! Heart

Occasional Contributor

Yes, I agree fully with this too.  This would also be particularly useful for using CTA's to drive popup modals identified through anchor IDs or CSS IDs.

 

Capture.PNG

 

@hubspot, can we make this happen?

Occasional Contributor

This is something that has come up on several of my projects. I would love this addition to the toolset.

New Contributor

100% agree, I would love to use CTAs for all of the reasons @ringo-at-wt mentioned as well, right now the experience you've described is what we are using and it's suboptimal. Would be great if HubSpot could implement this!

Regular Contributor

I totally agree! Please can someone provide a solution for this?

I want to use an Image CTA (button), so the anchor text solution is no option. At the moment I am using id="page-part" and linking the CTA to our url#page-part but this causes the page to reload, which is slower than scrolling, so unwelcome.

 

Thank you

Occasional Contributor

Does anyone have an update on this?

Occasional Contributor

Just chipping in that I'm having this exact issue as well and found this thread through a search on using same page CTA.

 

In the mean time I will use a link in a rich text field using the HTML - to add the button style.

Which looks like this -> 

<div style="text-align: center;">
<a href="/built-for/agencies#cta-link" class="smoothscroll btn btn-outline" rel=" noopener">Get in touch</a>
</div>

@hubspot -> Would be nice to have this as an option in the "official" CTA's components.,

 

Reply
0 Upvotes
Occasional Contributor

Actually Hubspot overrules the href in a rich text so the above is broken as well...

 

Stumped.

Reply
0 Upvotes
Occasional Contributor

A temporary solution (maybe): 

 

1) after you added your anchor link, use the following for the button <a href="#scrollUp" ..., or whatever name you assigned to the anchor link in your HTML.

 

2) in the page's advanced settings add the following jQuery code:

 

<script>
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();

var target = this.hash,
$target = $(target);

$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, function () {
window.location.hash = target;
});
});
});
</script>

 

Note: you can change '900' to a value that suits you best for the scrolling speed (the value is written in milliseconds, so that's 0.9s)