การทำให้เครือข่ายโฆษณาทำงานร่วมกับฟีเจอร์เกี่ยวกับการแปลใน Google Search
Google Search มีฟีเจอร์เกี่ยวกับการแปลหลายฟีเจอร์ที่ช่วยให้ผู้ใช้สามารถเข้าถึงเนื้อหาที่มีการแปล หากคุณทำธุรกิจเครือข่ายโฆษณาและโฆษณาของคุณทำงานไม่ถูกต้องในหน้าเว็บที่แปล คุณจะต้องทำตามขั้นตอนในคำแนะนำนี้เพื่อให้แน่ใจว่าโฆษณาจะแสดงหรือระบุแหล่งที่มาอย่างถูกต้อง
แนวทางของเรา
เมื่อผู้ใช้เข้าถึงเนื้อหาที่แปลโดย Google แปลภาษาในผลการค้นหาต่างๆ Google จะดึงหน้าเว็บจากผู้เผยแพร่โฆษณา เขียน URL แหล่งที่มาใหม่ และแปลหน้าเว็บหลังจากที่ผู้ใช้คลิกผลการค้นหาที่แปล
แปลง URL ของ Google แปลภาษาเป็น URL ต้นฉบับ
หากเป็นธุรกิจเครือข่ายโฆษณาที่ต้องอาศัย URL แหล่งที่มาของผู้เผยแพร่โฆษณา คุณจะต้องแปลง URL ของ Google แปลภาษาเพื่อให้แน่ใจว่าโฆษณาทำงานอย่างถูกต้อง ทำตามขั้นตอนต่อไปนี้เพื่อถอดรหัสชื่อโฮสต์ของผู้เผยแพร่โฆษณา
- ดึงคำนำหน้าโดเมนออกจากชื่อโฮสต์โดยนำคำต่อท้าย .translate.googออก
- แยกพารามิเตอร์ _x_tr_encตามอักขระ,(คอมมา) แล้วบันทึกเป็นencoding_list
- เพิ่มค่าพารามิเตอร์ _x_tr_hpไว้หน้าคำนำหน้าโดเมน (หากมี)
- หาก encoding_listมี1และเอาต์พุตขึ้นต้นด้วย1-ให้นำคำนำหน้า1-ออกจากเอาต์พุตในขั้นตอนที่ 2
- หาก encoding_listมี0และเอาต์พุตขึ้นต้นด้วย0-ให้นำคำนำหน้า0-ออกจากเอาต์พุตในขั้นตอนที่ 3 หากคุณนำคำนำหน้าออก ให้ตั้งค่าis_idnเป็นtrueมิเช่นนั้น ให้ตั้งค่าis_idnเป็นfalse
- นำอักขระ .(จุด) ไปแทนที่/\b-\b/(นิพจน์ทั่วไป)
- นำอักขระ -(ขีดกลางสั้น) ไปแทนที่อักขระ--(ขีดกลางสั้นคู่)
- หากตั้งค่า is_idnเป็นtrueให้เพิ่มคำนำหน้าxn--ของ Punycode
- ไม่บังคับ: แปลงเป็น Unicode
ตัวอย่างโค้ด JavaScript สำหรับการถอดรหัสชื่อโฮสต์จาก URL ของ Google แปลภาษา
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; }
สร้าง URL ใหม่
- ใช้ URL หน้าเว็บต้นฉบับในการนำชื่อโฮสต์ที่ถอดรหัสแล้วไปแทนที่ชื่อโฮสต์
- นำพารามิเตอร์ _x_tr_*ทั้งหมดออก
ทดสอบโค้ด
      คุณสร้างการทดสอบ 1 หน่วยสำหรับโค้ดได้โดยใช้ตารางต่อไปนี้ เมื่อพิจารณา proxyUrl แล้ว decodeHostname ต้องตรงกับค่าที่คาดไว้
    
ตารางต่อไปนี้ใช้ในการทดสอบการถอดรหัสชื่อโฮสต์ได้เท่านั้น คุณต้องตรวจสอบว่าเส้นทาง ส่วนย่อย และพารามิเตอร์ต้นฉบับของ URL ยังคงเหมือนเดิม
| 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) |