Home › Forums › Developers’ Hangout › [Developers’ Hangout] Add / Change parameter of URL and redirect to the new URL on button click
Tagged: Advertisment tracking
This topic contains 5 replies, has 2 voices, and was last updated by Hudson Atwell 4 months ago.
-
AuthorPosts
-
October 10, 2018 at 6:58 am #133809
Hi Hudson,
I know it is out of the scope but you already have helped me to adjust the code in this thread post.
This time it is in need to use the script not as auto-redirect but further more to be used to ad a button and by clicking to grab the URL parameter and forward to the setup URL.
Here is again the auto-redirect code in use, to be changed to use button click as an event to grab the parameters and forward to URL
<p><!-- Modify this according to your requirement - core script from https://gist.github.com/Joel-James/62d98e8cb3a1b6b05102 and suffix grabbing </p> <h3 style="text-align: center;"><span style="color: #ffffff; background-color: #039e00;">►Auto-redirecting after <span id="countdown">35</span> seconds◄</span></h3> <p><!-- JavaScript part --><br /><script type="text/javascript"> function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } // Total seconds to wait var seconds = 35; function countdown() { seconds = seconds - 1; if (seconds < 0) { // Chnage your redirection link here var tid = findGetParameter('tid'); window.location = "https://owndomain.com/option-page" + '?tid='+tid; } else { // Update remaining seconds document.getElementById("countdown").innerHTML = seconds; // Count down using javascript window.setTimeout("countdown()", 1000); } } // Run countdown function countdown(); </script></p>
Here the goal to reach:
1. A FB ad points to an optin page with tracking code: https://ownsite.com/optin-page/?tid=fbad1
2. at the optin-page there is a button with URL to forward to sales page, but if I add only the URL to forward, then the parameter “?tid=fbad1” is missing.
Therefore a script code shall be implemented to establish click buttons (also to style them or use images instead) and while clicking the button to forward to a different sales page with grabbing the suffix parameter form the current optin-page to forward then to sales-page https://ownsite.com/sales-page/?tid=fbad1It would be very helpful if you could help me with this also or point me to someone who maybe can solve this issue.
Best, Alex
P.S. Please find here the page where the code shall be added > https://www.2share.info/ql-cb2/?tid=codetesting
with screenshots where the parameters shall be implemented as buttons > https://www.screencast.com/t/uCYYaHVngOP and here the page-editor “profitbuilder” as styling editor in use https://www.screencast.com/t/saDYujTRfnOctober 10, 2018 at 11:30 pm #133813P.P.S. I guess the best solution would be to add a script to the functions.php which check if there are buttons in use on a page and if those buttons are clicked then check if the page URL has parameters included to be added to the URL setup for that button.
October 12, 2018 at 4:56 am #133817Hi Hudson,
I have now created this page to use for a testing purpose. https://www.2share.info/test-button-parameter-submission/?tid=buttonclicktest
There are 2 buttons added and the code shall be added to grab the url parameter after clicking the button to forward to the URL by adding the parameters in addition.
I have also added the auto-forward code, but this shall be only used as example to use the code to be customized for button click instead of auto forward.
Any ideas how to solve this?
Best Alex
<!-- Modify this according to your requirement – core script https://gist.github.com/Joel-James/62d98e8cb3a1b6b05102 and suffix grabbing https://support.inboundnow.com/support/topic/facebook-tracking-ids-not-working-after-form-submission/#post-133674--></p> <h3 style="text-align: center;"><span style="color: #ffffff; background-color: #039e00;">►Auto-redirecting after <span id="countdown">60</span> seconds◄</span></h3> <p><!-- JavaScript part --><br /><script type="text/javascript"> function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } // Total seconds to wait var seconds = 60; function countdown() { seconds = seconds - 1; if (seconds < 0) { // Chnage your redirection link here var tid = findGetParameter('tid'); window.location = "https://www.google.com/" + '?tid='+tid; } else { // Update remaining seconds document.getElementById("countdown").innerHTML = seconds; // Count down using javascript window.setTimeout("countdown()", 1000); } } // Run countdown function countdown(); </script>
October 12, 2018 at 4:22 pm #133821Hi Sorry for the delay.
I think I may can help.
For this testcase URL we want to add the tid to the two buttons:
https://www.2share.info/test-button-parameter-submission/?tid=buttonclicktestThey both have this class name “frb_button”, so we can use jQuery to change their destination URLS.
function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } /* loop through every button with this class and change destination URL */ jQuery('.frb_button').each(function() { var href = jQuery(this).prop('href'); jQuery(this).prop('href' , href + '?tid=' + findGetParameter('tid') ); });
notice I added the function findGetParameter into the mix because we depend on it. If it’s already added though through our prior code edits, then we won’t need to add it again.
We might need to wrap the code in a command that tells it not to run until the document is fully loaded. If that is the case then our code will/should look like this:
function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } /* wait til document is done loading */ jQuery(document).ready(function() { /* loop through every button with this class and change destination URL */ jQuery('.frb_button').each(function() { var href = jQuery(this).prop('href'); jQuery(this).prop('href' , href + '?tid=' + findGetParameter('tid') ); }); });
October 13, 2018 at 7:49 am #133827Hi Hudson,
THANK YOU VERY MUCH – IT WORKS PERFECT!
I hope you are well and the Hurricane “Michael” has not harmed you in any kind except the internet connection. I guess you need to settle over you Europe to get away from those weather problems and sorry for my pushing to get it done.
Many thanks again, and all the best from Germany!
AlexOctober 13, 2018 at 2:18 pm #133830Fantastic news happy to help!
Thank you also for the well wishes. We did not get it as bad as the people below us. Power went back out today. Internet still out too. Shelters are full. Traffic yucky. I’m really glad there is not another storm lined up behind it. I’m ready for cool weather!
Warm regards,
Hudson Atwell -
AuthorPosts
The topic ‘[Developers’ Hangout] Add / Change parameter of URL and redirect to the new URL on button click’ is closed to new replies.