Updating contact's profile manually
This article gives you instructions on how to update contact’s profile in Online marketing module. Contact’s information is being updated automatically as corresponding visitor performs certain actions on a live site (such as user login) or by submitting forms. However, you might want to fill in additional information about current contact. Example would be mapping visitor’s IP to a city using external service or updating contact’s job title according to visitor’s landing page.
First you need to determine where will be your code placed.
a) You might want to place your code into a web part. This scenario is most suitable for updating contact’s profile on specific pages.
b) You might want to place your code into global.asax.cs (CMS.AppBase.cs respectively). This is most suitable on updating contact’s profile on (almost) every request.
c) You might want to place your code into a method where new contact is being created - ContactHelper.GetNewContact().
Then you need to determine which way you will update contact’s profile.
a) You will have full access to ContactInfo object. This is appropriate when you are sure that OnlineMarketing module is present and you can reference library.
ContactInfo currentContact = OnlineMarketingContext.GetCurrentContact();
if ((currentContact != null) && String.IsNullOrEmpty(currentContact.ContactCity))
string city =
currentContact.ContactCity = city;
b) Another option is to update contact by using ModuleCommands. You don’t need to reference OnlineMarketing library and therefore this ways doesn’t depend if OnlineMarketing module is installed or not.
int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID();
if (contactId > 0)
string city =
bool allowOverwriteExistingData = false;
Dictionary<string, object> contactData = new Dictionary<string, object>();
Updating contact’s city as shown above is just only one attribute in many you can set. Another example would be: creating relations to accounts where is contact currently employed, setting academic titles based on information a visitor provides, setting contact’s ZIP based on his location, etc.
Online marketing guide
Kentico CMS API reference
Kentico CMS 6.0 and higher