Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Using marketing foundation to advertise on your site

With marketing foundation comes the ability to set up an advertising context to let your visitors know that there's a lot of great offers on your site. This article will feature an example of how to use the advertising system in marketing foundation to dynamically show banners with relevant information based on what they are browsing.

If you don't know about the basics of marketing foundation, please take the time to read about marketing foundation here.

Setting the stage

For this example, we’ll set up a dynamic campaign macro, that for every product page we see, output a banner if the right context requirements are met. Having a running site may result in multiple campaigns running at the same time, which may result in a lot of complexity in terms of resolving the right campaign items and displaying just the right information for the customers. To keep this as simple as possible, we’ll assume that we just need to output a text and an image on the top of our product page if the product runs in a campaign. For this example, we'll set up a campaign that awards a free gift if you buy a certain product - in this case, a free tie to go with a nice shirt. With that in mind, we are ready to configure our campaign item.

image

Configure metadata for campaign items

We need to configure metadata for our campaign items. For this purpose, we use definitions for campaign items and set up an image and description we can use as a teaser for the customer. We will create a campaign item definition "Product Campaigns" we can use for this purpose.

image

Setting this definition on our campaign item under "Overview" gives us an extra tab "ad" that allows us to insert a descriptive text and select an image from the media library.

image
image

Setting up the right context

We should set the Blue Kittens Mood Slim Fit Signature Shirt as our advertising context. Remember that advertising has nothing to do with the actual triggering of the discount - so we still need to set up the right act context (the same product) and select a free gift as the award - which in this case should be the tie. For the metadata, we'll select the image used for the tie, and a nice text that hopefully would persuade any man with style to get a shirt and a free tie :-)

image

Modifying our product template

Now that every bit of information is configured we just need to modify our product template to output the banner if the right context is met. For our code, we will assume that we only need to display information from the first targeted campaign item. Since the marketing library will give us a list, we'll just ask for the first one, if such exists.

Getting availableCampaignItems and metadata for advertise purposes

    Ucommerce.Api.IMarketingLibrary marketingLibrary = ObjectFactory.Instance.Resolve<Ucommerce.Api.IMarketingLibrary>();
    Ucommerce.Content.IImageService imageService = ObjectFactory.Instance.Resolve<IImageService>();
    
    var campaignItem = marketingLibrary.GetTargetedCampaignItems().FirstOrDefault();
    if (campaignItem != null)
    {
        string text = campaignItem.DynamicProperty<string>().Description;
        string imageId = campaignItem.DynamicProperty<string>().Image;
        string imageUrl = imageService.GetImage(imageId).Url;
    }
    
    

Summary

In this we have covered how to enable dynamic advertising using marketing foundation. We have:

  • configured a new campaign item definition "Product campaigns" with an image and text
  • Setup a campaign item that awards a free tie when buying a shirt, and set the definition to "Product campaigns" that will allow selecting an image and text to show in the frontend for the visitor
  • Setup advertise context to run on a product: 'Blue kittens Mood Slim Fit Signature Shirt'
  • Setup act context to run on a product: 'Blue kittens Mood Slim Fit Signature Shirt'
  • Configured a 'Hugo boss black tie' as a free gift that will be triggered if you buy the 'Blue kittens shirt'
  • Selected the image for the free gift tie as the image under the ad for our campaign item
  • Created a suitable text to help the visitor being persuaded to put the shirt into the basket and checking out.