On-line marketing macros

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 for your website. With on‑line marketing, macros are required when building conditions for:

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

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.

Getting Contact and Scoring data

The fundamental part of most on‑line marketing macros is the loading of a specific contact or its data. Use the following expressions for this purpose:

  • OnlineMarketingContext.CurrentContact - returns a ContactInfo object representing the current contact, i.e. the visitor who is viewing the website when the macro is resolved.
  • OnlineMarketingContext.CurrentContactID - returns the ID of the current contact.
  • Contact - you may use this expression when writing conditions for dynamic 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. OnlineMarketingContext.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 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).

Working with InfoObjectCollections

There are many ways how you can process InfoObjectCollection objects. For example:




OnlineMarketingContext.CurrentContact.Accounts.Exists(AccountName == "CompanyAccount")

Checks whether the current contact belongs to an account named CompanyAccount and returns the result as a boolean value.




OnlineMarketingContext.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

FilledFormFieldWithValue

Returns a bool representing if the contact has filled in a specific field in a specific form with a given text value.

  • Object contact - ContactInfo object of the contact that is to be evaluated.
  • Object formNameField - the name of the form combined with the specific field. Use the “<site name>;<form name>;<form field>” format. For example, “DancingGoat;ContactUs;FirstName”.
  • Object expectedValue - the value the field should contain.
  • Object lastXDays - optional parameter specifying, in days, how long ago at most the contact must have submitted the form. If not specified or 0, no time constraint is given on the method.



Contact.FilledFormFieldWithValue("DancingGoat;ContactUs;City", "Chicago", 7)

UnsubscribedFromAllEmails

Returns a bool representing if the contact has unsubscribed from all marketing emails.

  • Object contact - must contain the appropriate ContactInfo object of the contact that is to be evaluated.
  • Object lastXDays - optional parameter specifying, in days, how long ago at most the contact must have unsubscribed from all email campaigns.



OnlineMarketingContext.CurrentContact.UnsubscribedFromAllEmails(ToInt(14))

or




UnsubscribedFromAllEmails(OnlineMarketingContext.CurrentContact, ToInt(14))

SubscribedToNewsletter

Returns a bool representing if the contact is subscribed to a specified email campaign. Doesn’t work for contacts that are subscribed via a Contact group, Persona or a Role.

  • Object contact - must contain the appropriate ContactInfo object of the contact that is to be evaluated.
  • Object newsletterName - must contain the name of the specific email campaign.
  • Object lastXDays - optional parameter specifying, in days, how long ago at most the contact must have subscribed to the email campaign.



OnlineMarketingContext.CurrentContact.SubscribedToNewsletter("Coffee101", ToInt(14))

or




SubscribedToNewsletter(OnlineMarketingContext.CurrentContact, "Coffee101", ToInt(14))

IsInPersona

Returns a bool representing if the contact is assigned to a specified persona.

  • Object contact - must contain the appropriate ContactInfo object of the contact that is to be evaluated.
  • Object persona - must contain the appropriate PersonaInfo object of the contact that is to be evaluated.



IsInPersona(OnlineMarketingContext.CurrentContact, persona)

GetPersona

Returns the persona the contact is currently assigned to. Returns null if the contact is not assigned to a persona.

Note: Always use this method over the ContactPersona property, as this method is able to correctly take into account the persona selected in the preview mode.

  • Object contact - must contain the appropriate ContactInfo object of the contact that is to be evaluated.



OnlineMarketingContext.CurrentContact.GetPersona()

or




GetPersona(OnlineMarketingContext.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.
  • Object 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.



 OnlineMarketingContext.CurrentContact.LastActivityOfType("purchasedproduct")

or




LastActivityOfType(OnlineMarketingContext.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.
  • Object 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.



OnlineMarketingContext.CurrentContact.FirstActivityOfType("productaddedtowishlist")

IsInContactGroup

Checks if a contact belongs to a specific contact group and returns the result as a boolean value (true or false).

  • Object contact - used to specify the ContactInfo object representing the contact that will be checked.
  • Object contactGroupName - must contain the code name of the given contact group. You can enter the value as a string.



OnlineMarketingContext.CurrentContact.IsInContactGroup("MaleCustomers")

GetScore

Returns the total number of score points that a given contact has in a specified score (as an integer).

  • Object contact - used to specify the ContactInfo object representing the contact whose score points should be loaded.
  • Object scoreName - must contain the code name of the given score. You can enter the value as a string.



OnlineMarketingContext.CurrentContact.GetScore("InterestedInSmartphones")

GetEmailDomain

Read an e‑mail address and returns only its domain part (all characters after the “@” sign).

  • Object email - specifies the e-mail address from which the domain is taken. You can enter the address as a string.



OnlineMarketingContext.CurrentContact.ContactEmail.GetEmailDomain()

Scoring - Notification email template macros

You can place macros into the text of the Scoring - Notification e-mail e-mail template 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.

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, 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<A/B test code name> - returns the code name of the page variant assigned to the visitor by the specified A/B test.

  • Cookies.CMSMVT<MVT test code name> - returns the internal code name of the combination assigned to the visitor by the specified MVT test.

    Note: The internal MVT combination name is not the custom name set for the given combination, but an identifier in format Combination_<order number>. For example: Combination_003