|
||
You can use macro expressions to dynamically load values related to on‑line marketing features. 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:
•Content personalization variants
•Dynamic Contact groups
•Marketing automation triggers and process steps
You can also use on-line marketing macros in all other parts of Kentico CMS 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, where the system automatically ensures that the content is processed as a macro. For more information about possible macro options and syntax in general, please refer to the Development -> Macro expressions chapter in the Kentico CMS Developer's Guide.
The fundamental part of most on‑line marketing macros is the loading of a specific contact or its data. You may 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. It allows you to work with a general ContactInfo object. When the contact group is rebuilt, all contacts under the corresponding site (or from all sites in the system if the group is global) are processed and checked whether they fulfill the specified condition (e.g. 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:
•Accounts - InfoObjectCollection containing all accounts (AccountInfo objects) to which the given contact is assigned.
•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.
•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).
There are many ways how an InfoObjectCollection can be further processed. For example:
OnlineMarketingContext.CurrentContact.Accounts.Exists(AccountName == "CompanyAccount")
This sample macro 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.
Please see the Available macro methods topic in the Developer's Guide for a comprehensive list of the possible options.
You may also call the following methods inside macro expressions, which are specifically designed to help retrieve on‑line marketing data:
LastActivityOfType(Object contact, Object activityType)
Returns an ActivityInfo object representing the activity most recently logged for the specified contact.
•contact - this parameter must contain the appropriate ContactInfo object of the contact whose activity should be loaded.
•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.
Example:
LastActivityOfType(OnlineMarketingContext.CurrentContact, "purchasedproduct") |
or:
OnlineMarketingContext.CurrentContact.LastActivityOfType("purchasedproduct") |
FirstActivityOfType(Object contact, Object activityType)
Returns an ActivityInfo object representing the first activity logged for the specified contact.
•contact - this parameter must contain the appropriate ContactInfo object of the contact whose activity should be loaded.
•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(Object contact, Object contactGroupName)
Checks if a contact belongs to a specific contact group and returns the result as a boolean value (true or false).
•contact - this parameter is used to specify the ContactInfo object representing the contact that will be checked.
•contactGroupName - must contain the code name of the given contact group. You can enter the value as a string.
OnlineMarketingContext.CurrentContact.IsInContactGroup("MaleCustomers") |
GetScore(Object contact, Object scoreName)
This method returns the total number of score points that a given contact has in a specified score (as an integer).
•contact - used to specify the ContactInfo object representing the contact whose score points should be loaded.
•scoreName - must contain the code name of the given score. You can enter the value as a string.
OnlineMarketingContext.CurrentContact.GetScore("InterestedInSmartphones") |
GetEmailDomain(Object email)
This method may be used to read an e‑mail address and return only its domain part (all characters after the "@" sign).
•email - this parameter is used to specify the e-mail address from which the domain should be taken. You can enter the address as a string.
OnlineMarketingContext.CurrentContact.ContactEmail.GetEmailDomain() |
It is also possible to place macros into the text of the Scoring - Notification e-mail e-mail template, so you can dynamically load the appropriate values. This template is used for the automatic messages that inform administrators or marketers that a contact has reached a certain amount of score points. There are several special macros available for this purpose.
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.
If you wish to check whether the current visitor has arrived on the website as a result of a campaign, or passed through a page with an A/B or multivariate test, you can read the information from the appropriate browser cookie. The following macro expressions may be used to get the values of the given 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. Please note that this is not the custom name set for the combination, but an identifier in format Combination_<order number>, e.g. Combination_003.