Add Page URL Parameters to CTA

SOLVE
Highlighted
New Contributor

Hello,

 

I have a CTA on a page that is a landing page containing the usual utm_.* parameters plus some other ones. I need to get the parameters from the URL, for example...

 

?utm_source=a_source&arbitrary_param=arbitrary_value

 

...such that when the CTA on the page (in this case a button) is clicked, the parameters are then associated with the link that is redirected to as a result of the CTA, but in a slightly different format...

 

?attribute[utm_source]=a_source&attribute[arbitrary_param]=arbitrary_value

 

...is this possible?

 

Thanks,

 

Matthew

1 Accepted solution

Accepted Solutions
Highlighted
Solution
HubSpot Product Team

Hi Matthew,

 

I believe that you can add the params directly to the link when you're creating your CTA- they should be available on the destination URL.

 

For example, http://google.com?q=searchQuery 

 

If you need to dynamically pass params from one page to the next, I do not believe that is possible, due to the tracking redirect that takes place.

 

I hope that helps,

Anthony

View solution in original post

Reply
0 Upvotes
8 Replies 8
Highlighted
Solution
HubSpot Product Team

Hi Matthew,

 

I believe that you can add the params directly to the link when you're creating your CTA- they should be available on the destination URL.

 

For example, http://google.com?q=searchQuery 

 

If you need to dynamically pass params from one page to the next, I do not believe that is possible, due to the tracking redirect that takes place.

 

I hope that helps,

Anthony

View solution in original post

Reply
0 Upvotes
Highlighted
New Contributor

Hello Anthony,

 

I need the parameters to be dynamic as there will be a token UUID that will change each time, eg...

 

tid=693c68f5-e98b-4921-9e24-14feef8276c4

 

...needs to become...

 

attribute[tid]=693c68f5-e98b-4921-9e24-14feef8276c4

 

If this functionaliy is not available out of the box, I was thinking of adding some JavaScript to the page (hack) that would look for CTA links (this sort of thing; https://cta-service-cms2.hubspot.com/ctas...) and update them with the necessary extra parameters, but am not sure what form such parameters should take to ensure they survive the 30x redirects.

 

Thanks,

 

Matthew

Reply
0 Upvotes
Highlighted
HubSpot Product Team

Hi Matthew,

 

I see what you mean. As far as I know there is no way to pass a param that will survive the redirect. 

 

Best of luck,

Anthony

Reply
0 Upvotes
Highlighted
New Contributor
The saga continues
 
It turns out that...
 
{{ widget.cta_area }}
 
...generates something that looks like this...
 
hbspt.cta.load(158015, 'ccd39b7c-ae18-4c4e-98ee-547069bfbc5b');
 
 
The hbspt.cta.load function ends up calling, amongst other things, this...
 
displayCta
 
...which can be overridden with one's own function like this...
 
window.hbspt.cta.displayCta = function(pAccount, pCtaId, pMystery, a) {
...etc...
}
 
...the above function refers to 'this' which will not work, so another variable has to be set first that points to what should be 'this' and that variable used within the function, so...
 
var that = window.hbspt.cta;
 
window.hbspt.cta.displayCta = function(pAccount, pCtaId, pMystery, a) {
...
s.type = "text/javascript", s.async = !0, s.src=that.getCtaLoaderScriptSrc(account, ctaid, noideahowtochangethis, a), that.ctaLoaded = !1, that.onCTAReady = addParams, that.utils.log(pCtaId + " loading with src: " + s.src), (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(s);
...    
}
 
...within which one can intercept the onCTAReady event. In the above this was done with an addParams function in the hope that the CTA URL could be updated with extra parameters.
 
The above line (s.type....) generates a JavaScript tag that's appended to the DOM. When this parameter driven JavaScript is returned it contains the ultimate CTA destination in an <a> tag in the cta_dest_link attribute. It was hoped by updating this attribute that parameters could be added to the destination URL. Alas no, seems that this attribute is for reference only and changing it has no effect.
 
It now appears that Hack v2.0 is required, meaning that the original CTA is activated via an AJAX GET (so that Hubspot's internal tracking knows that it was), the results of the call then discarded (i.e. the built in redirection is not allowed to happen). Instead the updated URL is constructed (including the required parameters) and redirected to independently without using Hubspot at all. This will of course look like 'clickjacking'.
 
Is there really no way to transmit custom parameters to a CTA destination URL?
 
 
Highlighted
Visitor

Hello! Any update on this? We would also like to pass some dynamic parameters via a HubSpot CTA. This is a deal breaker for us.

 

Example:

- user enters https://mysite.com/?dynamic_param=hello

- clicks a HubSpot CTA that is configured to take the user https://mysubdomain.mysite.com/

- we want to append a query string to the cta_dest_link, so the user actually goes to https://mysubdomain.mysite.com/?dynamic_param=hello

Highlighted
Occasional Contributor

Hi,

 

Same request here.

If we can not track our campains pointing to the HS landings page then redirecting to our main site, we will be forced to stop using hubspot landing and/or cta and replace with another solution (looking for it now)

Regards,

Thomas

 

Highlighted
Occasional Contributor

Did anyone find another solution for this? We're looking outside of Hubspot too at this point.

Highlighted
Visitor

Hi guys,

 

Here is a little hack you can use to do it with some jquery in your page.

1) First check if you have a parameter

const url = window.location.href;
var params = url.split('?')[1];

2) Select all the links you want to change, for instance all link which end by mysubdomain.mysite.com  

var all_links = $("a[href$='mysubdomain.mysite.com']");

3) Change their url with parameters

var link_url = all_links.attr('href');
all_links.attr('href', link_url+"?"+params);

And here you go ! 🙂

Reply
0 Upvotes