Boite à outils Office

How to preview your Commerce Server marketing data

Commerce Server, Development Add comments

As you should know, Microsoft Commerce Server allows you to manage your marketing campaigns of your e-Commerce website through 2 modules of the Marketing System :

These two modules are all schedulable. Which means that you can set a start and end date for the display of an ad or on a discount application.

By default, the Marketing Business Tools allows you to preview the rendering of an ad:

image

But nothing on a discount… and my two cents, that like my customers, you will tell :”Hey, Gaël, it’s not enough! I need to view my ads or my discounts in my website. I have to be sure that everything is set up correctly…”

Ok, so it’s pretty easy to see the result of your marketing campaign items if they are all applicable right now. Just open your web application and that’s it Sourire However, don’t forget that you might have constrains on your ads or discounts like for example:

  • the ad can be displayable on a particular type of pages (home, products, basket, …),
  • the ad or the discount is eligible if the connected user meets the requirement like to be a man or a woman
  • etc, etc, … (if you have questions on all the different condition, do not hesitate to contact me Sourire)

image

But what can you do if your marketing campaign items are expected in 2 or 3 months? Do you have to wait the d day like you was expecting your first party? So, for sure the answer is…

… really depending of the quality of your Commerce Server Consultant/Expert Sourire Let’s pick up one of the below answers:

  • “That’s not possible at all! Commerce Server don’t do those kind of feature!”
  • “Change the server’s date and refresh your cache to see the result” (truthful!)
    • Handy if you have staging and live on the same box, isn’t it? Envieux 
    • Most of the time it’s an IT task, and I guess they have something else to do… (I do hope Ange)
      • Don’t forget to rollback the date, so again an IT task…
  • “Deactivate your eligible marketing campaign items and activate only the ones you want to test by changing the start date to the current day time.”
    • Need to have a staging environment
    • Painful, I have customer who has more than 100 advertisements and at least the same amount of discount…
    • Confusion when you have to reactivate the true eligible marketing campaign items
      • Have to be sure which have to be reactivate…
    • Possible errors when you modify the begin and end date
    • Some guys can tell you that a custom development for activating /deactivating a list of campaign items can be the solution. Right, but that’s still not an acceptable answer as you still have to tick/untick the campaign items…
  • “No worries, we have the solution!”…

The solution is pretty simple. Fist, you have to know that the Commerce Server runtime loads the different caches and context information during the first load of the application or each time the cache is refreshing. That’s of course for better performance considerations.

In the case of discouts and advertising the caching system is loaded by two stored procedures (and an another one called by these 2 stored procedures) which is located in the marketing system database:

  • mktg_spRuntimeLoadAdvertisements
  • mktg_spRuntimeLoadDiscounts
  • mktg_spRuntimeLoadReferenceTables

 

imageimageimage

=> These stored procedures are called at the first load or each time the caches are refreshing.

 

The Commerce Server team did a really great job with the caching system on discounts and advertisements. Indeed, it’s possible to tell to the runtime which stored procedures to load and so, we are now able to include our own logic within them.

The idea, here, is to have two applications. One for the preview and another one for the default behavior. In the preview web application, we will load our two new stored procedures by the runtime.

In order to do that, we will tell to the runtime to load our 2 stored procedures by modifying the web.config file, in the caches section web.config > CommerceServer > Caches (see MSDN: caches Element).

In the preview application web.config’s file we will changing the default caching section by:

<cache
    name="Advertising"
    type="Advertising" 
    refreshInterval="900" 
    retryInterval="30" 
    loaderProgId="Commerce.CSFLoadAdvertisements" 
    writerProgId="Commerce.CSFWriteEvents">
    <config
        key="LoadAdvertisementsProcedure" 
        value="spGael_staging_mktg_spRuntimeLoadAdvertisements" />
</cache>
<cache
    name="Discounts" 
    type="Discounts" 
    refreshInterval="0" 
    retryInterval="30" 
    loaderProgId="Commerce.CSFLoadDiscounts" 
    writerProgId="Commerce.CSFWriteEvents">
    <config 
        key="LoadDiscountsProcedure" 
        value="spGael_staging_mktg_spRuntimeLoadDiscounts" />
</cache>

The default behavior for the pipeline is to compare the start and end date with the current local time, but as you may know, changing that means re develop all the pipeline components and that’s of course not my solution Sourire. To workaround that, I will move back the start and end date by calculating the difference between the current date time and the preview date, and so retrieve it on all the scheduled discounts and advertisements.

Let’s execute the default stored procedure to load the advertisements caching system “mktg_spRuntimeLoadAdvertisements”:

image

Only the advertisements with the start and end date in the time frame of the 8th of July came up. For my post, I’ve created a new ad only visible between the 1st and the 31st of August:

image

If I execute again the stored procedure “mktg_spRuntimeLoadAdvertisements”, I got the exactly same result. Surprised? No! As my ad is not eligible. The start date is on the 1st of August and we are the 8th of July 2010:

image[21]

Now, copy and paste the “mktg_spRuntimeLoadAdvertisements” stored procedure code and create a new one call “spGael_staging_mktg_spRuntimeLoadAdvertisements”. Just change the start and end date by retrieving the days number between the preview date and now.

imageYou will note that the preview date is stored in a table called “altima_doPreview”. Like that, I can have a simple web part to change the preview date on the fly (don’t forget to refresh your cache).

If we now execute the stored procedure, we got just one result, because the preview date is on the 15th of August and only my ad is eligible:

image

Note that in my result, the start and end date have switched to 37 days back:

  • Start date: 1st August 2010 – 37 days => 25 June 2010
  • End date:, 31 August 2010 – 37 days => 25 July 2010

So, now time to run our preview web application (don’t forget to update the web.config) and miracle… my new ad is now displayed Sourire

image

Start the default behavior web application and note that my ad is not displayed

image

To finish, I give you here the code for the discounts stored procedure:

image

Hope this help!


JARAC 2011

3 Responses to “How to preview your Commerce Server marketing data”

  1. Tweets that mention How to preview your Commerce Server marketing data | Gael Duhamel [MVP] -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Gaël Duhamel. Gaël Duhamel said: How to preview your Commerce Server marketing data: As you should know, Microsoft Commerce Server allows y… http://bit.ly/aC1fk6 [...]

  2. Caesar Says:

    I like the idea, but modifying product stored procedures has the risk of side effects as bugs :-) .

    The two site idea is the right approach though. However, you want the preview site to have a “PREVIEW” environment variable defined (you can feed define this as a global variable in ASP.NET for the application). For example g_PREVIEW = True

    You can feed the g_PREVIEW value into the marketing rule by using a custom Profile definition (I believe there is a Targeting custom profile already built in).

    When you define the marketing rules simply add a rule that says Targeting.g_PREVIEW=TRUE OR (the rest of the rules).

    That way when you run on the preview app, the marketing rules will always fire.

    Note that everything will fire, so if you have a discount for Dec 1-24, and separately Dec 25-30, you will have both discounts fire at the same time.

    To refine the approach a bit, the Preview site should be sensitive to a user provided date and time to simulate such that the rules will preview on a specific date.

    You can do this using another global variable that takes a datetime value, same method as g_PREVIEW method above.

    Enjoy! :-)

  3. GaelDuhamel Says:

    Hi Caesar,

    Thanks for sharing, that’s cool :)

    The thing I don’t like with your solution is that you have to go to each of the campaign items you want to preview and set the targeting value to 1 or 1 and a date (if we go with your advanced solution)… So, if you have let’s say 50 ads and/or 20 discounts to preview it’s pretty tiring and hassle… As far as you have to rollback each ones to preview for other date range.

    With these stored procedures, you do not have to change something in the marketing items. Everything is loaded at the runtime with the stored procedures set in the web.config…

    For information, I haven’t change the built-in stored procedures. There are all new and loaded only by the preview web application. The production environnement is clean and the support is not break…

    Anyway, thanks again for your idea :)

Leave a Reply


WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in
Creative Commons License