The q parameter must be added to the code for a site. Through keyword substitution, you can dynamically pass values in the q parameter.
Let’s use JavaScript as an example. This will read the values <title>
tag and the title
meta tag.
To substitute keywords in a directink, place JavaScript before the closing </head>
tag.
<script> (function() { function run() { var className = ''; var suffix = className ? '.' + className : ''; var template = '{QUERY}'; var aels = document.querySelectorAll('a' + suffix + ', button' + suffix); var tel = document.querySelector('title'); var mel = document.querySelector('meta[name="og:title"]'); var keyword = (mel && mel.getAttribute('content')) || tel.innerHTML || document.title || ''; window.__bd_keyword = window.__bd_query = keyword; var arr = [].slice.call(aels); for (var i = 0; i < arr.length; i++) { var ael = arr[i]; var newHref = (ael.getAttribute('href') || '').replace(template, encodeURIComponent(keyword)); var newOnclick = (ael.getAttribute('onclick') || '').replace(template, encodeURIComponent(keyword)); ael.setAttribute('onclick', newOnclick); ael.setAttribute('href', newHref); } } if (window.document.readyState === 'interactive' || window.document.readyState === 'complete') { return run(); } else { window.document.addEventListener('DOMContentLoaded', run); } })(); </script>
Place the ad code according to the procedure we described in this guide:
<a href="http://example.com/r/?token=86985c2e6524f2e3de83ac75975c39c85bbd2b6d&q={QUERY}" target="_blank"><img src="https://i.ibb.co/3BN3yTx/Download-Button-PNG-Photo.png" alt="Download-Button" border="0" width="250"></a>
Note: the directlink must end with the q={QUERY} parameter.
The value of the q parameter is case sensitive: {QUERY} must be specified in capital letters. If you set parameters as {Query} or {query}, keyword substitution will not work.
Advanced substitution methods
Changing variables for searching keywords
If necessary, you can modify the script so that it gets the keyword from a different tag.
To do this, make changes to the following lines of the script:
var tel = document.querySelector('title'); var mel = document.querySelector('meta[name="og:title"]');
If you want to get keywords from page descriptions, the script should look like this:
var mel = document.querySelector('meta[name="og:description"]');
Adding new variables for keyword search
You can also add additional variables from which to take keywords. To do this, create a new variable.
As an example, let’s take the H1 heading from the page we are interested in and write it to the my_var variable:
var my_var = document.getElementsByTagName("h1")[0];
If there are no variables on the page, the empty string will become the value for the keyword variable. The modified script will look like this:
<script> (function() { function run() { var className = ''; var suffix = className ? '.' + className : ''; var template = '{QUERY}'; var aels = document.querySelectorAll('a' + suffix + ', button' + suffix); // DO NOT MODIFY THE CODE ABOVE //Example of new variables var tel = document.querySelector('description'); var mel = document.querySelector('meta[name="og:description"]'); var my_var = document.getElementsByTagName("h1")[0]; var keyword = (mel && mel.getAttribute('content')) || tel.innerHTML || document.title || my_var.innerHTML || ''; //End of example // DO NOT MODIFY THE CODE BELOW window.__bd_keyword = window.__bd_query = keyword; var arr = [].slice.call(aels); for (var i = 0; i < arr.length; i++) { var ael = arr[i]; var newHref = (ael.getAttribute('href') || '').replace(template, encodeURIComponent(keyword)); var newOnclick = (ael.getAttribute('onclick') || '').replace(template, encodeURIComponent(keyword)); ael.setAttribute('onclick', newOnclick); ael.setAttribute('href', newHref); } } if (window.document.readyState === 'interactive' || window.document.readyState === 'complete') { return run(); } else { window.document.addEventListener('DOMContentLoaded', run); } })(); </script>
Note: do not make changes to other parts of the JavaScript code as this may lead to errors.