Google Search provides several functions related to the translation that allow users to access the translated content. If your advertising network does not work properly on the translated web pages, you need to follow the recommendations given in this manual so that your ads are correctly displayed and attributes are correctly attached.
When users turn to the translated content provided by Google Translate from search results, Google receives a page from the publisher, changes the source URL and translates the web page after the user clicked to the translated result.
If your advertising network depends on the initial URL publisher, you need to convert the URL Google Translate so that the ads are displayed correctly. Follow these steps to decode the name of the publisher host:
function decodeHostname(proxyUrl) {
const parsedProxyUrl = new URL(proxyUrl);
const fullHost = parsedProxyUrl.hostname;
// 1. Извлеките префикс домена из имени хоста, удалив суффикс ".translate.goog"
let domainPrefix = fullHost.substring(0, fullHost.indexOf('.'));
// 2. Разделите параметр _x_tr_enc на части, используя запятую, и сохраните как encodingList
const encodingList = parsedProxyUrl.searchParams.has('_x_tr_enc') ?
parsedProxyUrl.searchParams.get('_x_tr_enc').split(',') : [];
// 3. Добавьте значение параметра _x_tr_hp к префиксу домена, если оно существует
if (parsedProxyUrl.searchParams.has('_x_tr_hp')) {
domainPrefix = parsedProxyUrl.searchParams.get('_x_tr_hp') + domainPrefix;
}
// 4. Удалите префикс '1-' из результата шага 2, если encodingList содержит '1' и результат начинается с '1-'.
if (encodingList.includes('1') && domainPrefix.startsWith('1-')) {
domainPrefix = domainPrefix.substring(2);
}
// 5. Удалите префикс '0-' из результата шага 3, если encodingList содержит '0' и результат начинается с '0-'.
// Установите isIdn в true, если префикс был удален, в false в противном случае.
let isIdn = false;
if (encodingList.includes('0') && domainPrefix.startsWith('0-')) {
isIdn = true;
domainPrefix = domainPrefix.substring(2);
}
// 6. Замените /-/ на точку (.)
// 7. Замените двойное тире на одно тире.
let decodedSegment = domainPrefix.replaceAll(/-/g, '.').replaceAll('--', '-');
// 8. Если isIdn равно true, добавьте префикс 'xn--'.
if (isIdn) {
decodedSegment = 'xn--' + decodedSegment;
}
return decodedSegment;
}
You can create unit tests for your code using the next table. When submitting Proxyurl, the Decodehostname function should return the expected value.
The following table is used only to test the name of the host. It is necessary to make sure that the path, fragment and original URL parameters are kept unchanged.
| Proxyurl | Decodehostname |
|---|---|
| HTTPS: // Example-Kom. Translavite. Hogo | example.com |
| HTTPS: //fo-example-kom. Translavite. Hogog | Fu. Example.kom |
| HTTPS: //fo--- Example-kom. Translavite. Hogog | FOOO-Example.Kom |
| HTTPS: //0-57XH060O-oKO.SALYT. GOOG/? _C_TR_ENTS = 0 | Hn-57XH060O.K. |
| https: // 1-en--us-example-com/? _x_tr_enc = 1 | EN-USA EXMPLE.K. |
| https: //lanfairpwlgwyngylgogogogorychwyrndrobwllantyogogogocho-co-uk.translate .GOOG/? _ x_TR_HP = lllanfairpwlgwyngylgogoGogoRndrobwllantysiliogogogoch.co.uk | Lllanfirepvlgvalgogergartychyrndrovlelandiliogogogochch.So.uk |
If you have questions about the integration of transfers on your site and the correct display of advertising, you can contact the SEO.computer SEO company for any issue for email info@seo.computer Or in WhatsApp +79202044461.
ID 168