---
title: On-line marketing macros
related:
  - https://docs.kentico.com/k12sp/macro-expressions.md
  - https://docs.kentico.com/k12sp/macro-expressions/writing-macro-conditions.md
  - https://docs.kentico.com/k12sp/macro-expressions/writing-macro-conditions/building-conditions-using-macro-rules.md
  - https://docs.kentico.com/k12sp/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/on-line-marketing-macros/improving-custom-macro-performance-in-scoring-and-contact-groups.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

You can use macro expressions to dynamically load values related to on‑line marketing applications. Properly using these expressions allows you to set up flexible content and behavior of your websites. With on‑line marketing, macros are required when building conditions for:

- Condition-based [Contact groups](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/segmenting-contacts-into-contact-groups.md)
- [Marketing automation triggers](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/marketing-automation/setting-triggers-for-automation-processes.md) and [process steps](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/marketing-automation/working-with-the-automation-process-designer.md)
- [Content personalization](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/content-personalization.md) variants on Portal Engine sites

You can also use on-line marketing macros in all other parts of Kentico where macros are supported.

> **Note:** **Note**
>
> All expressions described below are _context macros_, which means they must be enclosed in _{% %}_ parentheses when entered into text or other general fields. You do not need to use macro parentheses inside macro‑specific fields, such as condition editors.

> **Note:** **Limitations for MVC projects**
>
> For sites built using the [MVC development model](https://docs.kentico.com/k12sp/developing-websites/mvc-development-overview.md), the macro expressions described on this page can be used only for Kentico features managed from the administration interface (e.g. managing contact groups or defining automation triggers). Using the on-line marketing macros to render content on the pages of MVC live sites is not supported.

## Getting Contact and Scoring data

The fundamental part of most on‑line marketing macros is the loading of a specific [contact](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/working-with-contacts.md) or its data. Use the following expressions for this purpose:

- **ContactManagementContext.CurrentContact** – returns a _ContactInfo_ object representing the current contact, i.e. the visitor who is viewing the website when the macro is resolved.
- **ContactManagementContext.CurrentContactID** – returns the ID of the current contact.
- **Contact** – you may use this expression when writing conditions for condition-based contact groups or in marketing automation. The Contact macro allows you to work with a general _ContactInfo_ object. For example: _Contact.ContactGender == 1_

_ContactInfo_ objects serve as a way to access the values set for the given contact (e.g. _ContactManagementContext.CurrentContact.ContactLastName_). In addition to standard contact fields, you can also use the following advanced properties to get data related to the contact:

| ContactInfo property | Description                                                                                                                                                                                                                                         |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Accounts             | _InfoObjectCollection_ containing all accounts (_AccountInfo_ objects) to which the given contact is assigned.                                                                                                                                      |
| ContactGroups        | _InfoObjectCollection_ containing all contact groups (_ContactGroupInfo_ objects) that contain the given contact.                                                                                                                                   |
| LastActivity         | _ActivityInfo_ object representing the most recently logged [activity](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/tracking-contact-activities.md) for the given contact. |
| Orders               | _InfoObjectCollection_ containing all e‑commerce orders (_OrderInfo_ objects) made by the contact on the current site.                                                                                                                              |
| Processes            | _InfoObjectCollection_ containing all marketing automation processes in which the contact is running.                                                                                                                                               |
| PurchasedProducts    | _InfoObjectCollection_ containing all products (_SKUInfo_ objects) purchased by the contact across all sites in the system.                                                                                                                         |
| Wishlist             | _InfoObjectCollection_ containing all products (_SKUInfo_ objects) added to the wishlist of the given contact (across all sites in the system).                                                                                                     |

> **Tip:** **Working with InfoObjectCollections**
>
> There are many ways how you can process **InfoObjectCollection** objects. For example:
>
> ```csharp
>
> ContactManagementContext.CurrentContact.Accounts.Exists(AccountName == "CompanyAccount")
>
> ```
>
> Checks whether the current contact belongs to an account named _CompanyAccount_ and returns the result as a boolean value.
>
> ```csharp
>
> ContactManagementContext.CurrentContact.Orders.Exists(OrderTotalPrice > 500)
>
> ```
>
> Checks if the current contact has made an order with a total value greater than 500 of the given currency.

### On-line marketing macro methods

You can call the following methods inside macro expressions to retrieve on‑line marketing data:

| Method                                                                                                                                                                                                                                                                                                                                                    | Description / Parameters / Examples                                                                                                                                                                                                                                                 |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AgreedWithConsent                                                                                                                                                                                                                                                                                                                                         | Returns a _bool_ representing if the contact has given a consent specified in the parameter.                                                                                                                                                                                        |
| **ContactInfo contact** – contains _ContactInfo_ object of the contact that is to be evaluated.<br>**String consentName** – specifies the code name of the [consent declaration](https://docs.kentico.com/k12sp/configuring-kentico/data-protection/gdpr-compliance/creating-consents.md).                                                                |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.AgreedWithConsent("TrackingConsent")
 `                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                     |
| FilledFormFieldWithValue                                                                                                                                                                                                                                                                                                                                  | Returns a _bool_ representing if the contact has filled in a specific field in a specific form with a given text value.                                                                                                                                                             |
| **ContactInfo contact** – contains _ContactInfo_ object of the contact that is to be evaluated.<br>**String formNameField** – specifies the name of the form combined with the specific field. Use the ";;" format. For example, "DancingGoat;ContactUs;FirstName".<br>**String expectedValue** – specifies the value the field should contain.           |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.FilledFormFieldWithValue("DancingGoat;ContactUs;City", "Chicago")
 `                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                     |
| UnsubscribedFromAllEmails                                                                                                                                                                                                                                                                                                                                 | Returns a _bool_ representing if the contact has unsubscribed from all [marketing emails](https://docs.kentico.com/k12sp/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-email-marketing/integrating-email-feeds-into-sites.md). |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.                                                                                                                                                                                                                                            |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.UnsubscribedFromAllEmails()
 `                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                                                     |
| IsInPersona                                                                                                                                                                                                                                                                                                                                               | Returns a _bool_ representing if the contact is assigned to the specified persona.                                                                                                                                                                                                  |
| **ContactInfo contact** – contains the _ContactInfo_ object of the contact that is to be evaluated.<br>**Object persona** – must contain the appropriate  _PersonaInfo_  object of the contact that is to be evaluated.                                                                                                                                   |                                                                                                                                                                                                                                                                                     |
| ` 
IsInPersona(ContactManagementContext.CurrentContact, persona)
 `                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                                                     |
| GetPersona                                                                                                                                                                                                                                                                                                                                                | Returns the persona the contact is currently assigned to. Returns null if the contact is not assigned to a persona.<br>**Note:** Always use this method over the ContactPersona property, as this method can correctly take into account the persona selected in the preview mode.  |
| **ContactInfo contact** – contains the _ContactInfo_ object of the contact that is to be evaluated.                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.GetPersona()
 `<br>or<br>` 
GetPersona(ContactManagementContext.CurrentContact)
 `                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                     |
| LastActivityOfType                                                                                                                                                                                                                                                                                                                                        | Returns an _ActivityInfo_ object representing the activity most recently logged for the specified contact.                                                                                                                                                                          |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact whose activity should be loaded.<br>_**String activityType**_  – optional parameter that may be used to get the last activity of a specific type. The value must be entered as a string matching the code name of the appropriate activity type.                    |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.LastActivityOfType("purchasedproduct")
 `<br>or<br>` 
LastActivityOfType(ContactManagementContext.CurrentContact, "purchasedproduct")
 `                                                                                                                                                                       |                                                                                                                                                                                                                                                                                     |
| FirstActivityOfType                                                                                                                                                                                                                                                                                                                                       | Returns an _ActivityInfo_ object representing the first activity logged for the specified contact.                                                                                                                                                                                  |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact whose activity should be loaded.<br>_**String activityType**_  – optional parameter that may be used to get the first activity of a specific type. The value must be entered as a string matching the code name of the appropriate activity type.                   |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.FirstActivityOfType("productaddedtowishlist")
 `                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                     |
| IsInContactGroup                                                                                                                                                                                                                                                                                                                                          | Returns a _bool_ representing if the contact is a member of the specified contact group.                                                                                                                                                                                            |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String groupNames** – must contain the code name of the given contact group.                                                                                                                                                          |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.IsInContactGroup("MaleCustomers")
 `                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                     |
| GetScore                                                                                                                                                                                                                                                                                                                                                  | Returns the total number of score points that the given contact has in the specified score (as an _integer_).                                                                                                                                                                       |
| **Object contact** – specifies the _ContactInfo_ object representing the contact whose score points should be loaded.<br>**String scoreName** – must contain the code name of the given score.                                                                                                                                                            |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.GetScore("InterestedInSmartphones")
 `                                                                                                                                                                                                                                                                         |                                                                                                                                                                                                                                                                                     |
| GetEmailDomain                                                                                                                                                                                                                                                                                                                                            | Reads an email address and returns only its domain part (all characters after the "@" sign).<br>Note: The _GetEmailDomain_ method is not available when resolving macros in an external application using the _Kentico.Libraries_ NuGet package.                                    |
| **String email** – specifies the email address from which the domain is taken.                                                                                                                                                                                                                                                                            |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.ContactEmail.GetEmailDomain()
 `                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                     |
| CameToLandingUrl                                                                                                                                                                                                                                                                                                                                          | Returns a _bool_ representing if the contact has come to the landing page with the specified URL.                                                                                                                                                                                   |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String URL** – defines the part of URL specifying the landing page.                                                                                                                                                                   |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.CameToLandingUrl("smartphones")
 `                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                     |
| VisitedURL                                                                                                                                                                                                                                                                                                                                                | Returns a _bool_ representing if the contact has visited a page with the specified URL in the last X days.                                                                                                                                                                          |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String URL** – specifies the URL of the page that has been visited.<br>_**Int lastXDays**_ – optional parameter specifying how many days ago the page was visited. If you enter the zero value, no constraint is applied.             |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.VisitedUrl("smartphones", 5)
 `                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                     |
| VisitedSite                                                                                                                                                                                                                                                                                                                                               | Returns a _bool_ representing if the contact has visited the specified site.                                                                                                                                                                                                        |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String siteName** – specifies the code name of the site that has been visited.<br>_**Int lastXDays**_  – optional parameter specifying how many days ago the site was visited. If you enter the zero value, no constraint is applied. |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.VisitedSite("siteName", 0)
 `                                                                                                                                                                                                                                                                                  |                                                                                                                                                                                                                                                                                     |
| VisitedPage                                                                                                                                                                                                                                                                                                                                               | Returns a _bool_ representing if the contact has visited the specified page.                                                                                                                                                                                                        |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**GUID nodeGuid** – specifies the GUID of the page that has been visited.                                                                                                                                                               |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.VisitedPage(Documents["/Home"].NodeGuid)
 `                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                                                     |
| OpenedNewsletter                                                                                                                                                                                                                                                                                                                                          | Returns a _bool_ representing if the contact opened the specified newsletter.                                                                                                                                                                                                       |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**GUID newsletterGuid** – specifies the GUID of the newsletter that has been opened.                                                                                                                                                    |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.OpenedNewsletter(SiteObjects.Newsletters.CorporateNewsletter.NewsletterGuid)
 `                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                     |
| SubscribedToNewsletter                                                                                                                                                                                                                                                                                                                                    | Returns a _bool_ representing if the contact is subscribed to the specified newsletter.                                                                                                                                                                                             |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String newsletterName** – must contain the name of the specific newsletter.                                                                                                                                                           |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.SubscribedToNewsletter(SiteObjects.Newsletters.Coffee101)
 `                                                                                                                                                                                                                                                   |                                                                                                                                                                                                                                                                                     |
| VotedInPoll                                                                                                                                                                                                                                                                                                                                               | Returns a _bool_ representing if the contact has voted in the poll.                                                                                                                                                                                                                 |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**GUID pollGuid** – specifies the GUID of the poll that has been voted in.                                                                                                                                                              |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.VotedInPoll(SiteObjects.Polls.NewWebsitePoll.PollGuid)
 `                                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                                                                     |
| IsInRoles                                                                                                                                                                                                                                                                                                                                                 | Returns a _bool_ representing if the contact is assigned to any of the specified roles.                                                                                                                                                                                             |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String roleGuids** – specifies the GUIDs of the roles that the contact is assigned to. The GUIDs of the individual roles are separated with a semicolon.                                                                              |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.IsInRoles(SiteObjects.Roles.CMSBasicUsers.RoleGuid + ";" + SiteObjects.Roles.CMSDesigner.RoleGuid)
 `                                                                                                                                                                                                          |                                                                                                                                                                                                                                                                                     |
| IsInCommunityGroup                                                                                                                                                                                                                                                                                                                                        | Returns a _bool_ representing if the contact is a member of the specified community group.                                                                                                                                                                                          |
| **Object contact** – must contain the appropriate _ContactInfo_ object of the contact that is to be evaluated.<br>**String groupGuids** – specifies the GUID of the community groups that the contact is a member of. The GUIDs of the individual groups are separated with a semicolon.                                                                  |                                                                                                                                                                                                                                                                                     |
| ` 
ContactManagementContext.CurrentContact.IsInCommunityGroup(SiteObjects.Groups.American_travelers.GroupGuid + ";" + SiteObjects.Groups.Australian_travelers.GroupGuid)
 `                                                                                                                                                                               |                                                                                                                                                                                                                                                                                     |
| ActivityLinkedToObject                                                                                                                                                                                                                                                                                                                                    | Returns a _bool_ representing if the activity is linked to the given object by GUID or code name.                                                                                                                                                                                   |
| **AcrivityInfo activity** – contains the _ActivityInfo_ object of the activity that is to be evaluated.<br>**String objectType** – specifies the type of the object to which the activity is linked.<br>**String objectIdentifier** – identifies the object in the given object type by GUID or code name.                                                |                                                                                                                                                                                                                                                                                     |
| ` 
Activity.LinkedToObject("polls.poll", "NewWebsitePoll")
 `                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                     |

### Scoring - Notification email template macros

You can place macros into the text of the **Scoring - Notification email** [ template](https://docs.kentico.com/k12sp/configuring-kentico/managing-email-templates.md) to dynamically load values. The system uses this template for the automatic messages that inform administrators or marketers that a contact has reached a certain amount of [score points](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/scoring-contacts.md).

The **{% ScoreValue %}** expression returns the current number of score points for the given contact.

Additionally, you can access the following related objects and their properties (e.g. _{% Score.ScoreDisplayName %}_ etc.):

- **{% Score %}** – _ScoreInfo_ object representing the given score.
- **{% Contact %}** – _ContactInfo_ object of the contact that has reached the designated number of score points.

## Getting Campaign, A/B test and MVT test data

If you wish to check whether the current visitor has arrived on the website via a [campaign](https://docs.kentico.com/k12sp/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns.md), or passed through a page with an A/B or multivariate test, you can read the information from the appropriate browser cookie. Use the following macro expressions to get the necessary values from the cookies:

- **Cookies.Campaign** – returns the name of the campaign assigned to the visitor.
- **Cookies.CMSAB** – returns JSON data identifying the page variant assigned to the visitor by the specified A/B test, and information about performed conversions.
- **Cookies.CMSMVT** – returns JSON data identifying the combination assigned to the visitor by the specified MVT test.
