{"action":"created","issue":{"url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/11","labels_url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/11/comments","events_url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/11/events","html_url":"https://github.com/PromInc/organic-search-analytics/issues/11","id":120715723,"number":11,"title":"Country Filter","user":{"login":"sugarbeatsthat","id":16185657,"avatar_url":"https://avatars.githubusercontent.com/u/16185657?v=3","gravatar_id":"","url":"https://api.github.com/users/sugarbeatsthat","html_url":"https://github.com/sugarbeatsthat","followers_url":"https://api.github.com/users/sugarbeatsthat/followers","following_url":"https://api.github.com/users/sugarbeatsthat/following{/other_user}","gists_url":"https://api.github.com/users/sugarbeatsthat/gists{/gist_id}","starred_url":"https://api.github.com/users/sugarbeatsthat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sugarbeatsthat/subscriptions","organizations_url":"https://api.github.com/users/sugarbeatsthat/orgs","repos_url":"https://api.github.com/users/sugarbeatsthat/repos","events_url":"https://api.github.com/users/sugarbeatsthat/events{/privacy}","received_events_url":"https://api.github.com/users/sugarbeatsthat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-07T07:25:59Z","updated_at":"2015-12-11T04:57:26Z","closed_at":null,"body":"Hi Brian,\r\n\r\nAwesome job with this program and installation guide! I'm a complete novice at all this, but I just finished setting it up on my server, and it was all very easy.\r\n\r\nI just wondered, is it complicated to set up a country filter for the reports? Can I do it by just adding a few lines to one of the PHP files? Have been having a look through the files, but nothing's jumping out at me. Would really appreciate a few pointers on how to do this.\r\n\r\nAndy"},"comment":{"url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/comments/163839774","html_url":"https://github.com/PromInc/organic-search-analytics/issues/11#issuecomment-163839774","issue_url":"https://api.github.com/repos/PromInc/organic-search-analytics/issues/11","id":163839774,"user":{"login":"PromInc","id":7319505,"avatar_url":"https://avatars.githubusercontent.com/u/7319505?v=3","gravatar_id":"","url":"https://api.github.com/users/PromInc","html_url":"https://github.com/PromInc","followers_url":"https://api.github.com/users/PromInc/followers","following_url":"https://api.github.com/users/PromInc/following{/other_user}","gists_url":"https://api.github.com/users/PromInc/gists{/gist_id}","starred_url":"https://api.github.com/users/PromInc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PromInc/subscriptions","organizations_url":"https://api.github.com/users/PromInc/orgs","repos_url":"https://api.github.com/users/PromInc/repos","events_url":"https://api.github.com/users/PromInc/events{/privacy}","received_events_url":"https://api.github.com/users/PromInc/received_events","type":"User","site_admin":false},"created_at":"2015-12-11T04:57:26Z","updated_at":"2015-12-11T04:57:26Z","body":"Hi Andy,\r\n\r\nThanks for the kudos - good to hear that a novice was able to figure it out.  My goal has been to make this something that is usable by all.  Sadly there are a few semi-technical items to put in place, but there's only so much I can do.  ;)\r\n\r\nAdmittedly, country is something that is a bit of an oversight on my part.  The tool is not designed to capture country data at this time.  Certainly something that should be in this tool.\r\n\r\nIf you are feeling ambitious, I think it could be possible with a bit of work...  I'll do my best to try and walk through it here, but I'll be honest I'm speaking this in theory and not out of code I've put in place (at this time at least....).  But this is a feature that I will make into the codebase at some point.\r\n\r\nI should say though, the steps below will get the country data captured to the database.  Getting it to integrate to the reporting at this time is another can of worms I don't want to touch just yet.  I'm in the middle of a bit of a revamp on the reporting and what exists currently is too rudimentary.  I'm not saying it couldn't be integrated to what is there currently, and I think if you poke around in the reporting code enough you should be able to make something work.\r\n\r\n## Database update\r\nThe database doesn't have a column to hold country data.  So that'd be the first step.  Use PhpMyAdmin or whatever database access you have to add a **country** column to the **search_analytics** table.  I'd suggest setting it to varchar(10).\r\n\r\n## API Request Update\r\nNext we need to modify the API request to capture the country field.  There are two ways to approach this depending on how you run the tool.\r\n\r\n### GUI Method\r\nIF you use the website interface only and do not utilize a CRON job or other programatic method to request data, then you'll need to make a small code tweak.  The big downside here is that as new versions get released this will get over-written and you'll need to re-apply this modification.\r\n\r\nChange [Line 23 of inc/code/dataCapture.php](https://github.com/PromInc/organic-search-analytics/blob/master/organic-search-analytics/inc/code/dataCapture.php#L23) from:\r\n```\r\n'dimensions' => array('query','device'),\r\n```\r\nto:\r\n```\r\n'dimensions' => array('query','device','country'),\r\n```\r\n\r\n### Programatic Method\r\nIf you are using a CRON job or other programatic method to trigger the API request to Google, then you could simply do an override in your request.  There are several [data capture parameters](https://github.com/PromInc/organic-search-analytics/wiki/Data-Capture-Parameters) that allow you to make the same change that was made above but via a request as opposed to in the code.\r\n\r\nYour request would look something like this:\r\n```\r\n... inc/code/dataCapture.php?dimensions=query,device,country ...\r\n```\r\n\r\n## Data Import Update\r\nLastly we need to write the country data to the database.  For this, go to [line 64 of inc/code/wmpimport.php](https://github.com/PromInc/organic-search-analytics/blob/master/organic-search-analytics/inc/code/wmtimport.php#L64) and change it from:\r\n```\r\n$import = \"INSERT into \".MySQL::DB_TABLE_SEARCH_ANALYTICS.\"(domain, date, search_engine, search_type, device_type, query, impressions, clicks, ctr, avg_position) values('$domain', '$date', 'google', '$searchType', '$deviceType', '{$recordData['keys'][0]}','{$recordData['impressions']}','{$recordData['clicks']}','{$recordData['ctr']}','{$recordData['position']}')\";\r\n```\r\nto:\r\n```\r\n$import = \"INSERT into \".MySQL::DB_TABLE_SEARCH_ANALYTICS.\"(domain, date, search_engine, search_type, device_type, query, country, impressions, clicks, ctr, avg_position) values('$domain', '$date', 'google', '$searchType', '$deviceType', '{$recordData['keys'][0]}', '{$recordData['keys'][2]}','{$recordData['impressions']}','{$recordData['clicks']}','{$recordData['ctr']}','{$recordData['position']}')\";\r\n```\r\n\r\n## Test Your Code\r\nThat should be it - your next data capture should pull in country data.\r\n\r\nLet me know how this goes for you.  Your comments will help to ensure this gets integrated correctly into a future release."}}