Googlebooks শনাক্ত করুন

গুগলবুকস অ্যান্ড্রয়েড প্রযুক্তি স্ট্যাকের উপর নির্মিত এবং ক্রোমওএস-এর ডেস্কটপ ভিত্তির সাথে যুক্ত। বেশিরভাগ ওয়েব অ্যাপ্লিকেশন অন্য যেকোনো ডেস্কটপ ডিভাইসের মতোই গুগলবুকসে চলবে এবং ক্রোমওএস-এর মতো একই ইউজার এজেন্ট স্ট্রিং দেখতে পাবে:

Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0; Safari/537.36

To identify Googlebooks more accurately, for example, for analytics, or to direct users to download your compatible Android app, you need to request two User-Agent Client Hints : the Platform and the Mobile client hints. Both of these are low entropy hints , allowing you to get them without additional requests or permissions, just like you do with the User-Agent string. You can incorporate them directly into your existing detection.

ইউএ-সিএইচ হেডার গুগলবুকসের জন্য মান
Sec-CH-UA-Platform "Android"
Sec-CH-UA-Mobile ?0 (মিথ্যা)

ব্রাউজারে এটি শনাক্ত করতে, navigator.userAgentData API ব্যবহার করুন:

const isGooglebook = window?.navigator?.userAgentData?.platform === 'Android' && window?.navigator?.userAgentData?.mobile === false;

ইউজার-এজেন্ট রিডাকশনের কারণে, Platform ক্লায়েন্ট হিন্ট বা ইউজার এজেন্ট স্ট্রিং-এ গুগলবুকস-এর জন্য নির্দিষ্ট কোনো প্ল্যাটফর্ম যোগ করা হয়নি। তাই, গুগলবুকস এবং ক্রোমওএস-এর পূর্ববর্তী সংস্করণের মধ্যে একটি পার্থক্য নিশ্চিত করার জন্য, ক্লায়েন্ট হিন্টটি পরিবর্তন করে "Android" করা হয়েছে, যা নির্দেশ করে যে গুগলবুকস অ্যান্ড্রয়েড অ্যাপের সাথে সামঞ্জস্যপূর্ণ।

সার্ভার-সাইড সনাক্তকরণ

যেহেতু এই দুটিই লো এন্ট্রপি ক্লায়েন্ট হিন্ট, তাই ক্লায়েন্টের প্রাথমিক অনুরোধের সাথেই এগুলো আপনার সার্ভারে পাঠানো হবে এবং আপনি নিম্নলিখিত উপায়গুলোর যেকোনো একটিতে এগুলো সংগ্রহ করতে পারবেন:

নোড.জেএস

const platform = req.headers['sec-ch-ua-platform'] || 'Not Sent';
const mobile = req.headers['sec-ch-ua-mobile'] || 'Not Sent';

const cleanPlatform = platform.replace(/"/g, '');
const isGooglebook = cleanPlatform === 'Android' && mobile === '?0';

জাভা

String platform = exchange.getRequestHeaders().getFirst("Sec-CH-UA-Platform");
 if (platform == null) platform = "Not Sent";

String mobile = exchange.getRequestHeaders().getFirst("Sec-CH-UA-Mobile");
if (mobile == null) mobile = "Not Sent";

String cleanPlatform = platform.replace("\"", "");
boolean isGooglebook = cleanPlatform.equals("Android") && mobile.equals("?0");

রুবি

mobile = req['Sec-CH-UA-Mobile'] || 'Not Sent'

clean_platform = platform.gsub('"', '')
is_googlebook = clean_platform == 'Android' && mobile == '?0'

পাইথন

platform = self.headers.get('Sec-CH-UA-Platform', 'Not Sent')
mobile = self.headers.get('Sec-CH-UA-Mobile', 'Not Sent')

clean_platform = platform.replace('"', '')
is_googlebook = clean_platform == 'Android' and mobile == '?0'

পিএইচপি

$mobile = $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ?? 'Not Sent';

$cleanPlatform = str_replace('"', '', $platform);
$isGooglebook = ($cleanPlatform === 'Android' && $mobile === '?0');

যান

platform := r.Header.Get("Sec-CH-UA-Platform")
if platform == "" {
  platform = "Not Sent"
}
mobile := r.Header.Get("Sec-CH-UA-Mobile")
if mobile == "" {
  mobile = "Not Sent"
}

cleanPlatform := strings.ReplaceAll(platform, "\"", "")
isGooglebook := cleanPlatform == "Android" && mobile == "?0"

অন্যান্য দরকারী ক্লায়েন্ট পরামর্শ

While the Platform and Mobile client hints are enough to let you know your users are using a Googlebook, you may want more information about their device. The [Sec-CH-UA](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Sec-CH-UA) client hint returns a comma-separated list of the major browser version and other brands associated with the device, which is more straightforward to parse than doing so from the User-Agent string. There's also the Form Factors client hint ( Sec-CH-UA-Form-Factors ), a high entropy hint , that provides a comma-separated list of form factors for the given device (Desktop, Tablet, Mobile, Automotive, and so on). While this is often a single form factor, all applicable form factors could be included, so a detachable device may return "Desktop", "Tablet" , for example. আপনার ব্যবহারকারীরা ঠিক কোন ফর্ম ফ্যাক্টর ব্যবহার করছেন তা জানা যদি জরুরি হয়, এবং শুধু এটি যে একটি মোবাইল অ্যান্ড্রয়েড ডিভাইস নয় তা জানাটাই যথেষ্ট না হয়, তাহলে আপনি Critical-CH হেডারটি ব্যবহার করতে পারেন:

GET / HTTP/1.1
Host: example.com

HTTP/1.1 200 OK
Content-Type: text/html
Accept-CH: Sec-CH-UA-Form-Factors
Vary: Sec-CH-UA-Form-Factors
Critical-CH: Sec-CH-UA-Form-Factors

যদি ক্লায়েন্ট Accept-CH হেডারটি প্রসেস করার পর কোনো গুরুত্বপূর্ণ ইঙ্গিত অন্তর্ভুক্ত করে, তবে এটি অনুরোধটি পুনরায় চেষ্টা করবে। এর ফলে আপনি প্রাথমিক প্রতিক্রিয়ার পরিবর্তে একটি অপ্টিমাইজ করা পৃষ্ঠা পরিবেশন করতে পারবেন। যেহেতু এটি একটি অতিরিক্ত রাউন্ড ট্রিপ যোগ করে, তাই এটি কেবল সেইসব গুরুত্বপূর্ণ পৃষ্ঠা পরিবর্তনের জন্য ব্যবহার করুন যেগুলোর জন্য জরুরি তথ্যের প্রয়োজন হয়।