Skip to content

Commit 795d214

Browse files
committed
add logic to determine which country code to use
1 parent dcf36c2 commit 795d214

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/page/slidedown/ChannelCaptureContainer.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ interface TypeSpecificVariablePayload {
3030
tabIndex: number;
3131
}
3232

33+
export function getCountryCodeFromLocale(
34+
callback: (countryCode: string) => void,
35+
): void {
36+
try {
37+
const locale = navigator.language || 'en-US';
38+
const parts = locale.split('-');
39+
const countryCode = parts[parts.length - 1]?.toLowerCase(); // handle things like en-US / zh-Hans-CN
40+
callback(countryCode || 'us');
41+
} catch (error) {
42+
callback('us');
43+
}
44+
}
45+
3346
export default class ChannelCaptureContainer {
3447
public smsInputFieldIsValid = true;
3548
public emailInputFieldIsValid = true;
@@ -194,6 +207,8 @@ export default class ChannelCaptureContainer {
194207
{
195208
autoPlaceholder: 'off',
196209
separateDialCode: true,
210+
initialCountry: 'auto',
211+
geoIpLookup: getCountryCodeFromLocale,
197212
},
198213
);
199214
} else {

0 commit comments

Comments
 (0)