<commit_before>---
gallery: true
categories:
- enrich profile
---
## Add country to the user profile

This rule will add a `country` attribute to the user based on their ip address.

```js
function (user, context, callback) {
  user.country = context.request.geoip.country_name;

   // Example geoip object:
   // "geoip": {
   //    "country_code": "AR",
   //    "country_code3": "ARG",
   //    "country_name": "Argentina",
   //    "region": "05",
   //    "city": "Cordoba",
   //    "latitude": -31.41349983215332,
   //    "longitude": -64.18109893798828,
   //    "continent_code": "SA",
   //    "time_zone": "America/Argentina/Cordoba"
   //  }

  callback(null, user, context);
}
```<commit_msg>Check that geoip object exists<commit_after>---
gallery: true
categories:
- enrich profile
---
## Add country to the user profile

This rule will add a `country` attribute to the user based on their ip address.

```js
function (user, context, callback) {
  if (context.request.geoip) {
    user.country = context.request.geoip.country_name;
  }
  
   // Example geoip object:
   // "geoip": {
   //    "country_code": "AR",
   //    "country_code3": "ARG",
   //    "country_name": "Argentina",
   //    "region": "05",
   //    "city": "Cordoba",
   //    "latitude": -31.41349983215332,
   //    "longitude": -64.18109893798828,
   //    "continent_code": "SA",
   //    "time_zone": "America/Argentina/Cordoba"
   //  }

  callback(null, user, context);
}
```
{'fraction_non_alphanumeric': 0.17438692098092642, 'fraction_numerical': 0.047683923705722074, 'mean_word_length': 2.6271604938271604, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5791063', 'n_tokens_mistral': 567, 'n_tokens_neox': 514, 'n_words': 124}