Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Giúp mạng quảng cáo phối hợp với các tính năng liên quan đến dịch thuật của Google Tìm kiếm.
Google Tìm kiếm cung cấp một số tính năng liên quan đến dịch thuật, cho phép người dùng truy cập vào nội dung đã dịch. Nếu bạn đang điều hành một mạng quảng cáo và quảng cáo của bạn không hoạt động đúng cách trên các trang web đã dịch, thì bạn cần làm theo các bước trong hướng dẫn này để đảm bảo quảng cáo của bạn hiển thị hoặc phân bổ chính xác.
Phương pháp của chúng tôi
Khi người dùng truy cập vào nội dung đã dịch do Google Dịch cung cấp ngay trong kết quả tìm kiếm, Google sẽ truy xuất trang từ nhà xuất bản, rồi viết lại URL nguồn và dịch trang web sau khi người dùng nhấp vào kết quả đã dịch.
Chuyển đổi URL do Google Dịch cung cấp sang URL nguyên gốc
Nếu bạn đang chạy một mạng quảng cáo dựa trên URL nguồn của nhà xuất bản, thì bạn cần chuyển đổi URL do Google Dịch cung cấp để đảm bảo quảng cáo của bạn hoạt động bình thường. Hãy thực hiện theo các bước sau để giải mã tên máy chủ của nhà xuất bản:
- Trích xuất tiền tố miền khỏi tên máy chủ bằng cách xóa hậu tố
.translate.goog
.
- Tách thông số
_x_tr_enc
theo ký tự ,
(dấu phẩy) và lưu dưới dạng encoding_list
.
- Thêm giá trị của thông số
_x_tr_hp
vào tiền tố miền (nếu có).
- Nếu
encoding_list
chứa 1
và kết quả bắt đầu bằng 1-
, hãy xóa tiền tố 1-
khỏi kết quả của bước 2.
- Nếu
encoding_list
chứa 0
và kết quả bắt đầu bằng 0-
, hãy xóa tiền tố 0-
khỏi kết quả của bước 3. Nếu bạn đã xóa tiền tố, hãy đặt is_idn
thành true
. Nếu không, hãy đặt is_idn
thành false
.
- Thay thế
/\b-\b/
(biểu thức chính quy) bằng ký tự .
(dấu chấm).
- Thay thế ký tự
--
(dấu gạch nối đôi) bằng ký tự -
(dấu gạch ngang).
- Nếu bạn đặt
is_idn
thành true
, hãy thêm tiền tố punycode xn--
.
- Không bắt buộc: Chuyển đổi sang Unicode.
Mã JavaScript mẫu để giải mã tên máy chủ từ URL của Google Dịch
function decodeHostname(proxyUrl) {
const parsedProxyUrl = new URL(proxyUrl);
const fullHost = parsedProxyUrl.hostname;
// 1. Extract the domain prefix from the hostname, by removing the
".translate.goog" suffix
let domainPrefix = fullHost.substring(0, fullHost.indexOf('.'));
// 2. Split _x_tr_enc parameter by "," (comma), save as encodingList
const encodingList = parsedProxyUrl.searchParams.has('_x_tr_enc') ?
parsedProxyUrl.searchParams.get('_x_tr_enc').split(',') :
[];
// 3. Prepend value of _x_tr_hp parameter to the domain prefix, if it exists
if (parsedProxyUrl.searchParams.has('_x_tr_hp')) {
domainPrefix = parsedProxyUrl.searchParams.get('_x_tr_hp') + domainPrefix;
}
// 4. Remove '1-' prefix from the output of step 2 if encodingList contains
// '1' and the output begins with '1-'.
if (encodingList.includes('1') && domainPrefix.startsWith('1-')) {
domainPrefix = domainPrefix.substring(2);
}
// 5. Remove '0-' prefix from the output of step 3 if encodingList contains
// '0' and the output begins with '0-'.
// Set isIdn to true if removed, false otherwise.
let isIdn = false;
if (encodingList.includes('0') && domainPrefix.startsWith('0-')) {
isIdn = true;
domainPrefix = domainPrefix.substring(2);
}
// 6. Replace /\b-\b/ (regex) with '.' (dot) character.
// 7. Replace '--' (double hyphen) with '-' (hyphen).
let decodedSegment =
domainPrefix.replaceAll(/\b-\b/g, '.').replaceAll('--', '-');
// 8. If isIdn equals true, add the punycode prefix 'xn--'.
if (isIdn) {
decodedSegment = 'xn--' + decodedSegment;
}
return decodedSegment;
}
Tạo lại URL
- Sử dụng URL của trang gốc, thay thế tên máy chủ bằng tên máy chủ đã được giải mã.
- Loại bỏ tất cả thông số
_x_tr_*
.
Kiểm tra mã
Bạn có thể tạo các bài kiểm thử đơn vị cho mã của mình bằng cách sử dụng bảng sau. Với proxyUrl
, decodeHostname
phải khớp với giá trị dự kiến.
Bạn chỉ có thể sử dụng bảng sau để kiểm tra kết quả giải mã tên máy chủ. Bạn cần đảm bảo đường dẫn, phân đoạn và thông số nguyên gốc của URL được giữ nguyên.
proxyUrl
|
decodeHostname
|
https://example-com.translate.goog
|
example.com
|
https://foo-example-com.translate.goog
|
foo.example.com
|
https://foo--example-com.translate.goog
|
foo-example.com
|
https://0-57hw060o-com.translate.goog/?_x_tr_enc=0
|
xn--57hw060o.com (⚡😊.com)
|
https://1-en--us-example-com/?_x_tr_enc=1
|
en-us.example.com
|
https://0-en----w45as309w-com.translate.goog/?_x_tr_enc=0
|
xn--en--w45as309w.com (en-⚡😊.com)
|
https://1-0-----16pw588q-com.translate.goog/?_x_tr_enc=0,1
|
xn----16pw588q.com (⚡-😊.com)
|
https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=l
|
llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk
|
https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=www-l
|
www.llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk
|
https://a--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-com.translate.goog/?_x_tr_hp=a--xn--xn--xn--xn--xn--------------------------a
|
a-xn-xn-xn-xn-xn-------------aa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com
|
https://g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b-com.translate.goog/?_x_tr_enc=0&_x_tr_hp=0-
|
xn--g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b.com (💖🌲😊💞🤷♂️💗🌹😍🌸🌺😂😩😉😒😘💕🐶🐱🐭🐹🐰🐻🦊🐇😺.com)
|
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-04 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-04 UTC."],[[["\u003cp\u003eAd networks need to adjust how they handle Google Translate URLs to ensure ads function correctly on translated pages.\u003c/p\u003e\n"],["\u003cp\u003eA process is outlined to decode Google Translate URLs back to the original publisher's URL, involving extracting and manipulating URL components.\u003c/p\u003e\n"],["\u003cp\u003eProvided JavaScript code offers a solution to decode the hostname from Google Translate URLs.\u003c/p\u003e\n"],["\u003cp\u003eReconstructing the full original URL involves replacing the decoded hostname and removing Google Translate-specific parameters.\u003c/p\u003e\n"],["\u003cp\u003eA table with sample URLs and expected decoded hostnames aids in testing the implementation.\u003c/p\u003e\n"]]],["Ad networks must decode Google Translate URLs to ensure ads function on translated pages. This involves extracting the domain prefix, splitting the `_x_tr_enc` parameter, prepending the `_x_tr_hp` parameter, conditionally removing prefixes based on `encoding_list`, replacing hyphens, and adding a punycode prefix if `is_idn` is true. Finally, reconstruct the original URL by replacing the hostname with the decoded one and removing `_x_tr_*` parameters. Sample JavaScript code and test cases are provided.\n"],null,["# Ad Networks & Translation Search Features | Google Search Central\n\nEnabling your ad network to work with translation-related Google Search features\n================================================================================\n\n\nGoogle Search offers several [translation-related features](/search/docs/appearance/translated-results)\nthat enable users to access translated content. If you run an ad network and your ads aren't\nworking properly on translated web pages, you'll need to follow the steps in this guide to\nmake sure your ads render or attribute correctly.\n\nOur approach\n------------\n\n\nWhen users access translated content provided by [Google\nTranslate](https://translate.google.com/about/) from within search results, Google retrieves the page from the publisher, rewrites\nthe source URL, and translates the web page after the user clicks the translated result.\n\nConvert the Google Translate URL to the original URL\n----------------------------------------------------\n\n\nIf you run an ad network that relies on the publisher's source URL, you'll need to convert the\nGoogle Translate URL to make sure your ads are working properly. Follow these steps to decode the publisher's hostname:\n\n1. Extract the domain prefix from the hostname, by removing the `.translate.goog` suffix.\n2. Split the `_x_tr_enc` parameter by the `,` (comma) character and save it as `encoding_list`.\n3. Prepend the value of the `_x_tr_hp` parameter to the domain prefix, if it exists.\n4. If `encoding_list` contains `1` and the output begins with `1-`, remove the `1-` prefix from the output of step 2.\n5. If `encoding_list` contains `0` and the output begins with `0-`, remove the `0-` prefix from the output of step 3. If you removed the prefix, set `is_idn` to `true`. Otherwise, set `is_idn` to `false`.\n6. Replace `/\\b-\\b/` (regex) with the `.` (dot) character.\n7. Replace the `--` (double hyphen) character with the `-` (hyphen) character.\n8. If `is_idn` is set to `true`, add the punycode prefix `xn--`.\n9. **Optional**: Convert to Unicode.\n\n### Sample JavaScript code for decoding the hostname from a Google Translate URL\n\n```gdscript\nfunction decodeHostname(proxyUrl) {\n const parsedProxyUrl = new URL(proxyUrl);\n const fullHost = parsedProxyUrl.hostname;\n // 1. Extract the domain prefix from the hostname, by removing the\n \".translate.goog\" suffix\n let domainPrefix = fullHost.substring(0, fullHost.indexOf('.'));\n\n // 2. Split _x_tr_enc parameter by \",\" (comma), save as encodingList\n const encodingList = parsedProxyUrl.searchParams.has('_x_tr_enc') ?\n parsedProxyUrl.searchParams.get('_x_tr_enc').split(',') :\n [];\n\n // 3. Prepend value of _x_tr_hp parameter to the domain prefix, if it exists\n if (parsedProxyUrl.searchParams.has('_x_tr_hp')) {\n domainPrefix = parsedProxyUrl.searchParams.get('_x_tr_hp') + domainPrefix;\n }\n\n // 4. Remove '1-' prefix from the output of step 2 if encodingList contains\n // '1' and the output begins with '1-'.\n if (encodingList.includes('1') && domainPrefix.startsWith('1-')) {\n domainPrefix = domainPrefix.substring(2);\n }\n\n // 5. Remove '0-' prefix from the output of step 3 if encodingList contains\n // '0' and the output begins with '0-'.\n // Set isIdn to true if removed, false otherwise.\n let isIdn = false;\n if (encodingList.includes('0') && domainPrefix.startsWith('0-')) {\n isIdn = true;\n domainPrefix = domainPrefix.substring(2);\n }\n\n // 6. Replace /\\b-\\b/ (regex) with '.' (dot) character.\n // 7. Replace '--' (double hyphen) with '-' (hyphen).\n let decodedSegment =\n domainPrefix.replaceAll(/\\b-\\b/g, '.').replaceAll('--', '-');\n\n // 8. If isIdn equals true, add the punycode prefix 'xn--'.\n if (isIdn) {\n decodedSegment = 'xn--' + decodedSegment;\n }\n return decodedSegment;\n}\n```\n\nReconstruct the URL\n-------------------\n\n1. Using the original page URL, replace the hostname with the decoded hostname.\n2. Remove all `_x_tr_*` parameters.\n\nTest your code\n--------------\n\n\nYou can create unit tests for your code using the following table. Given a `proxyUrl`,\nthe `decodeHostname` must match the expected value.\n\n\nThe following table can only be used to test the hostname decoding. You'll need to ensure that\nthe path, fragment, and original parameters of the URL are preserved as is.\n\n| `proxyUrl` | `decodeHostname` |\n|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `https://example-com.translate.goog` | `example.com` |\n| `https://foo-example-com.translate.goog` | `foo.example.com` |\n| `https://foo--example-com.translate.goog` | `foo-example.com` |\n| `https://0-57hw060o-com.translate.goog/?_x_tr_enc=0` | `xn--57hw060o.com (⚡😊.com)` |\n| `https://1-en--us-example-com/?_x_tr_enc=1` | `en-us.example.com` |\n| `https://0-en----w45as309w-com.translate.goog/?_x_tr_enc=0` | `xn--en--w45as309w.com (en-⚡😊.com)` |\n| `https://1-0-----16pw588q-com.translate.goog/?_x_tr_enc=0,1` | `xn----16pw588q.com (⚡-😊.com)` |\n| `https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=l` | `llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk` |\n| `https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=www-l` | `www.llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk` |\n| `https://a--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-com.translate.goog/?_x_tr_hp=a--xn--xn--xn--xn--xn--------------------------a` | `a-xn-xn-xn-xn-xn-------------aa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com` |\n| `https://g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b-com.translate.goog/?_x_tr_enc=0&_x_tr_hp=0-` | `xn--g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b.com (💖🌲😊💞🤷♂️💗🌹😍🌸🌺😂😩😉😒😘💕🐶🐱🐭🐹🐰🐻🦊🐇😺.com)` |"]]