preserve url parameters from affliliate sites

Just in case somebody else has a similar problem I managed to solve it using this plug in

https://offers.sportingblog.gr/wp-admin/plugin-install.php?tab=plugin-information&plugin=header-and-footer-scripts

and then I added on the footer script the following code

<script type="text/javascript">
function getQueryParams(qs) {
qs = qs.split("+").join(" ");
var params = {}, tokens,   
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])]
= decodeURIComponent(tokens[2]);
}
return params;
}

var query = getQueryParams(document.location.search);
jQuery('a').each(function () {
var href = jQuery(this).attr('href');
if (href) {
href += (href.match(/\?/) ? '&' : '?') + 'affiliate=" + query.affiliate + "&pname=" + query.pname;
jQuery(this).attr("href', href);
}
});
</script>