Tech Support Posted November 16, 2020 Share Posted November 16, 2020 KVS doesn't support video popularity stats per country yet, but it is possible to emulate this for the end users, providing some personal attitude to every visitor: Step 1. In /admin/include/pre_initialize_page_code.php add the following line: $_GET['GEOIP_COUNTRY_CODE'] = $_REQUEST['GEOIP_COUNTRY_CODE'] = strtolower($_SERVER['GEOIP_COUNTRY_CODE']); This is needed to pass environmental variable with country code to request variables, that can be used by KVS site engine. Step 2. In Website UI -> Texts add the following text that will be rendered as a header: External ID: videos.list_title_by_country Default: Popular in %1% <img class="flag" title="%1%" alt="%2%" src="/static/images/flags/%2%.gif"> This text also contains IMG with reference to flag image. Step 3. Open Website UI -> Pages -> Index -> Videos Watched Right Now for editing. Change its Template code to the following: {{query_kvs select="single" table="list_countries" where_country_code=$smarty.get.GEOIP_COUNTRY_CODE where_language_code="en" assign="country"}} {{assign var="country_title" value=$country.title}} {{if !$country_title || $country.is_system==1}} {{assign var="list_videos_title" value=$lang.videos.list_title_watched_right_now}} {{else}} {{assign var="list_videos_title" value=$lang.videos.list_title_by_country|replace:"%1%":$country.title|replace:"%2%":$smarty.get.GEOIP_COUNTRY_CODE|smarty:nodefaults}} {{/if}} {{assign var="list_videos_use_h1" value="true"}} {{include file="include_list_videos_block_common.tpl"}} NOTE: KVS only supports country names in English and Russian languages, if your site is in Russian please change where_language_code="en" with "ru" to have country name in Russian. In block settings down the page specify GEOIP_COUNTRY_CODE under Dynamic HTTP parameters. This is needed for correct caching logic for this block. If you don't do that, KVS admin panel will show error that using $smarty.get.GEOIP_COUNTRY_CODE variable will not work correctly. The code does the following. First it queries KVS database and selects country record that matches the current visitor's country code using query_kvs template function. Then it checks whether any non-system country record is found (system countries are some satellite ISPs and anonymous proxies). If nothing is found, this code will show old "Videos Watched Right Now" text. Otherwise it will show the new text with country code and flag icon. Step 4. For better icon styling add this block into theme CSS file: h1 img.flag, h2 img.flag { vertical-align: middle; } 1 Quote Link to comment Share on other sites More sharing options...
davex Posted November 26, 2020 Share Posted November 26, 2020 On 11/16/2020 at 8:51 AM, Tech Support said: Step 4. For better icon styling add this block into theme CSS file: h1 img.flag { vertical-align: middle; } Thanks! referred to in step 4, in all-responsive-metal.css ? I have added the text at the end: h1 img.flag { vertical-align: middle; } but the flag icon is not centered. Quote Link to comment Share on other sites More sharing options...
Tech Support Posted November 26, 2020 Author Share Posted November 26, 2020 We updated this code in post, could be that in your case it is using H2 to render the header. Try that. Another possible issue is that CSS file is cached in your browser and your changes are not loaded. Try to check in another browser. Quote Link to comment Share on other sites More sharing options...
davex Posted November 26, 2020 Share Posted November 26, 2020 9 hours ago, Tech Support said: We updated this code in post, could be that in your case it is using H2 to render the header. Try that. Another possible issue is that CSS file is cached in your browser and your changes are not loaded. Try to check in another browser. Solved, thanks. Quote Link to comment Share on other sites More sharing options...
Emilia Posted March 10, 2021 Share Posted March 10, 2021 Hi, A little update, since mod_geoip is now retired, people are encouraged to use the new mod_maxminddb intead. https://github.com/maxmind/mod_maxminddb To fix the above code, all you need to do is replace GEOIP_COUNTRY_CODE to MM_COUNTRY_CODE everywhere. Everything else remains the same Quote Link to comment Share on other sites More sharing options...
Tech Support Posted March 11, 2021 Author Share Posted March 11, 2021 5 hours ago, Emilia said: To fix the above code, all you need to do is replace GEOIP_COUNTRY_CODE to MM_COUNTRY_CODE everywhere. Everything else remains the same No, no, if another module uses another ENV variable to store country code (e.g. MM_COUNTRY_CODE instead of GEOIP_COUNTRY_CODE needed by KVS), then better add this line into /admin/include/setup.php to move country code to the needed variable: $_SERVER['GEOIP_COUNTRY_CODE'] = $_SERVER['MM_COUNTRY_CODE']; This will also ensure that all other KVS functionality that relies on GEOIP will function correctly. 1 Quote Link to comment Share on other sites More sharing options...
Emilia Posted March 11, 2021 Share Posted March 11, 2021 (edited) Hi, I noticed I have this in my setup.php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $_SERVER['ORIG_REMOTE_ADDR']=$_SERVER['REMOTE_ADDR']; $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_FORWARDED_FOR']; if (strpos($_SERVER['REMOTE_ADDR'],',')!==false) { $_SERVER['REMOTE_ADDR']=trim(substr($_SERVER['REMOTE_ADDR'],0,strpos($_SERVER['REMOTE_ADDR'],','))); } } elseif (isset($_SERVER['HTTP_X_REAL_IP'])) { $_SERVER['ORIG_REMOTE_ADDR']=$_SERVER['REMOTE_ADDR']; $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP']; } if (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) { $_SERVER['GEOIP_COUNTRY_CODE']=$_SERVER['HTTP_CF_IPCOUNTRY']; } if (function_exists('geoip_country_code_by_name')) { $_SERVER['GEOIP_COUNTRY_CODE'] = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']); } Where should I add this? $_SERVER['GEOIP_COUNTRY_CODE'] = $_SERVER['MM_COUNTRY_CODE']; I dont use cloudflare so i probably don't need any HTTP_CF_IPCOUNTRY header Edited March 11, 2021 by Emilia Quote Link to comment Share on other sites More sharing options...
Tech Support Posted March 11, 2021 Author Share Posted March 11, 2021 8 minutes ago, Emilia said: Where should I add this? Just after all this block. This block is designed in the same way to detect country from Cloudflare headers. 1 Quote Link to comment Share on other sites More sharing options...
davex Posted March 11, 2021 Share Posted March 11, 2021 15 hours ago, Tech Support said: Just after all this block. This block is designed in the same way to detect country from Cloudflare headers. Hello, so for correct operation you have to replace this code: $_SERVER['GEOIP_COUNTRY_CODE']=$_SERVER['HTTP_CF_IPCOUNTRY']; for this? $_SERVER['GEOIP_COUNTRY_CODE'] = $_SERVER['MM_COUNTRY_CODE']; Quote Link to comment Share on other sites More sharing options...
Tech Support Posted March 12, 2021 Author Share Posted March 12, 2021 6 hours ago, davex said: Hello, so for correct operation you have to replace this code: $_SERVER['GEOIP_COUNTRY_CODE']=$_SERVER['HTTP_CF_IPCOUNTRY']; for this? $_SERVER['GEOIP_COUNTRY_CODE'] = $_SERVER['MM_COUNTRY_CODE']; No need to replace anything, this code is not for all users, this code is for specific question asked above. If you also have a case, when country code is put into MM_COUNTRY_CODE environment variable, then you also need to add this code. If not, then nothing should be changed / replaced / added. 1 Quote Link to comment Share on other sites More sharing options...
prvtzone Posted June 5 Share Posted June 5 I just tried and followed the all steps but for me nothing changed on the homepage. Its still the same as "Videos Being Watched" . It can be cache but i tried incognito mode and other browsers but its still the same. Am i doing anything wrong ? i followed every step in the tutorial . Quote Link to comment Share on other sites More sharing options...
Tech Support Posted June 5 Author Share Posted June 5 Please create support ticket. It may be possible that your server doesn't have the needed GEOIP module to identify country by IP. This module is not part of KVS. Quote Link to comment Share on other sites More sharing options...
viper Posted June 5 Share Posted June 5 Quote KVS doesn't support video popularity stats per country yet, Is there any plan to support this in the future? Quote Link to comment Share on other sites More sharing options...
Tech Support Posted June 6 Author Share Posted June 6 We don't see any good solution for this at the moment due to performance implications. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.