Hi Matthew!
We already spoke on the phone last week, but I just wanted to update the community with our answer. At this point in time, we don’t have any direct way to do this within the app - however - with a bit of javascript this should be achievable. We haven’t tested any solutions so far, but this should be feasible if you have a developer to build this out for your team.
Is there a way you could provide an example on how this can be executed in javascript? Thanks
Hey guys,
At this point I don’t have a script on hand that you could test out, but when I asked my dev team about it before they mentioned it should be possible (in theory) with a bit of javascript development. We don’t quite have the bandwidth to dig into this at this time, but if anyone in the Community is able to figure out a solution we would be happy to update this post. Hope this helps!
Hi,
We did something similar. But instead of dynamically changing a button URL we changed an iFrame URL based on a UTM parameter.
The URL in the iFrame has the following format:
www.example.com/landingpage/ '-thedynamicpart-' /subpage
The script pulls the UTM parameter 'utm_affiliate' from the unbounce parent url and rewrites the URL of the iFrame (with id 'frame1'), so it now includes this value. I tried to adapt the script so that it works for a button url instead, but without any luck. I think it should be relatively easy though. Maybe someone else can help out...
Hi,
We did something similar. But instead of dynamically changing a button URL we changed an iFrame URL based on a UTM parameter.
The URL in the iFrame has the following format:
www.example.com/landingpage/'-thedynamicpart-'/subpage
The script pulls the UTM parameter ‘utm_affiliate’ from the unbounce parent url and rewrites the URL of the iFrame (with id ‘frame1’), so it now includes this value. I tried to adapt the script so that it works for a button url instead, but without any luck. I think it should be relatively easy though. Maybe someone else can help out…
function getURLParameter(name) {
return decodeURIComponent((new RegExp('w?|&]' + name + '=' + '(+^&;]+?)(&|#|;|$)').exec(location.search)||.,""])h1].replace(/\+/g, '%20'))||null;
}
// Get the utm affiliate parameter
var utmAffiliate = getURLParameter('utm_affiliate');
// Get the iframe url
var iframeUrl = document.getElementById('frame1').src;
// Make sure the utm_affiliate param and the iframe url are existing
if (utmAffiliate !== null && typeof iframeUrl !== 'undefined') {
// Pattern for finding the http(s)://-part in the URL
var pattern = /(\b(https?:\/\/)(p-A-Z0-9+&@#\/%?=~_|!:,.;]*~-A-Z0-9+&@#\/%=~_|]))/i;
if (pattern.test(iframeUrl)) {
// Split the remaining URL at the '/'
var urlParts = RegExp.$3.split('/');
// Change the iframe affiliate with the utm param
var removed = urlParts.splice(2, 1, utmAffiliate);
// Generate the new URL
var newIframeUrl = RegExp.$2 + urlParts.join('/');
// Change the iframe URL
document.getElementById('frame1').src = newIframeUrl;
}
}
Hi,
We did something similar. But instead of dynamically changing a button URL we changed an iFrame URL based on a UTM parameter.
The URL in the iFrame has the following format:
www.example.com/landingpage/'-thedynamicpart-'/subpage
The script pulls the UTM parameter ‘utm_affiliate’ from the unbounce parent url and rewrites the URL of the iFrame (with id ‘frame1’), so it now includes this value. I tried to adapt the script so that it works for a button url instead, but without any luck. I think it should be relatively easy though. Maybe someone else can help out…
<br /> function getURLParameter(name) {<br /> return decodeURIComponent((new RegExp('w?|&]' + name + '=' + '(+^&;]+?)(&|#|;|$)').exec(location.search)||.,""])h1].replace(/\+/g, '%20'))||null;<br /> }<br /> <br /> // Get the utm affiliate parameter<br /> var utmAffiliate = getURLParameter('utm_affiliate');<br /> <br /> // Get the iframe url<br /> var iframeUrl = document.getElementById('frame1').src;<br /> <br /> // Make sure the utm_affiliate param and the iframe url are existing<br /> if (utmAffiliate !== null && typeof iframeUrl !== 'undefined') {<br /> <br /> // Pattern for finding the http(s)://-part in the URL<br /> var pattern = /(\b(https?:\/\/)(p-A-Z0-9+&@#\/%?=~_|!:,.;]*~-A-Z0-9+&@#\/%=~_|]))/i;<br /> <br /> if (pattern.test(iframeUrl)) {<br /> // Split the remaining URL at the '/'<br /> var urlParts = RegExp.$3.split('/');<br /> <br /> // Change the iframe affiliate with the utm param<br /> var removed = urlParts.splice(2, 1, utmAffiliate);<br /> <br /> // Generate the new URL<br /> var newIframeUrl = RegExp.$2 + urlParts.join('/');<br /> <br /> // Change the iframe URL<br /> document.getElementById('frame1').src = newIframeUrl;<br /> }<br /> }
</pre><p>
This is a really crafty workaround. Great to see that you’re pushing the boundaries!
Hey Matt did you ever find a solution for this? I just posted a new thread looking for the same thing you were here.
I did but haven’t posted the jscript here. Sorry will do that tonight. Stay tuned!
can you paste the script? thanks in advance!
In case anyone was still needing this or finds this later, this does the job perfectly: https://community.unbounce.com/tips-scripts-43/dynamic-links-based-on-url-parameters-4599#:~:text=You%20will%20use%20the%20multiple,parameter%20on%20your%20Unbounce%20page.