Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- (function() {
- // List of domains to decorate (without https or trailing slash)
- var domainsToDecorate = ['booker.com', 'somedomain.com'];
- // Value to be set as linker param
- var referrerDomain = 'ref-domain=' + document.location.hostname + '-praba-test';
- // Get all the links
- var links = document.querySelectorAll('a');
- // Filter the required domains
- for (var linkIndex = 0; linkIndex < links.length; linkIndex++) {
- for (var domainIndex = 0; domainIndex < domainsToDecorate.length; domainIndex++) {
- if (links[linkIndex].href.indexOf(domainsToDecorate[domainIndex]) > -1 && links[linkIndex].href.indexOf("#") === -1) {
- links[linkIndex].href = decorateUrl(links[linkIndex].href);
- }
- }
- }
- // decorates the URL with query params
- function decorateUrl(urlToDecorate) {
- urlToDecorate = (urlToDecorate.indexOf('?') === -1) ? urlToDecorate + '?' : urlToDecorate + '&';
- return urlToDecorate + '&' + referrerDomain;
- }
- // Append value as query parameter
- function getQueryParam(name) {
- if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(window.location.search)) return decodeURIComponent(name[1]);
- }
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement