1

I have a DXA 2.2 web app set up along with the XO module. Promotions created in the "CME targeting section" are working fine when I am using OOTB trigger types (like browser type etc.).

Now I am trying to create a custom trigger type, a very simple boolean based trigger type. I was thinking that it may be possible to write custom trigger types without writing any cartridge. With that understanding I wrote some code in httpmodule and code is pretty simple and looks like:

        Uri uri = new Uri("taf:claim:demo:showpromotion");
        if (!AmbientDataContext.CurrentClaimStore.Contains(uri))
        {
            AmbientDataContext.CurrentClaimStore.Put(uri, true, ClaimValueScope.Session);
        }

This code is adding a claim to the claim store. I configured samrttergetconf and ambiend_data_conf in the application along with microservices (Session enabled content service) so that this claim is forwarded. Corresponding files form my web app are shown below:

enter image description here

enter image description here

But in the smart target Model builder, in its ExecuteSmartTargetQuery method, my custom trigger is not returned from the AmbientDataHelper.GetTriggers(ClaimStore) method call.

I have not written any cartridge and I am trying to set the claims from my dotnet application only. So my questions are:

  1. Is it possible to use custom triggers without writing any cartridge for them? or writing a cartridge is mandatory?
  2. If it should work without a cartridge, then what am I missing, and why my custom trigger is not returned from the AmbientDataHelper.GetTriggers method call?
3
0

In order to further troubleshoot copy, this QueryBuilder.aspx page to your DXA website root folder and change the values according to your environment and try to validate against your trigger types and regions check the response.

<%@ Page Language="C#" %>
<%@ Import Namespace="Tridion.SmartTarget.Query.Builder" %>
<%@ Import Namespace="Tridion.SmartTarget.Analytics" %>
<%@ Import Namespace="Tridion.SmartTarget.Query" %>
<%@ Import Namespace="Tridion.SmartTarget.Utils" %>
<%@ Import Namespace="Tridion.ContentDelivery.AmbientData" %>
<%@ Import Namespace="Newtonsoft.Json" %>
<%@ Import Namespace="Newtonsoft.Json.Serialization" %>
<%@ Import Namespace="Newtonsoft.Json.Converters" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
    protected void Execute(QueryBuilder queryBuilder)
    {
        var resultSet = queryBuilder.Execute();
        var jsonSettings = new JsonSerializerSettings
        {
            Formatting = Formatting.Indented,
            ContractResolver = new CamelCasePropertyNamesContractResolver(),
            Converters = { new StringEnumConverter() }
        };
        
        Response.ContentType = "application/json";
        Response.Write(JsonConvert.SerializeObject(resultSet, jsonSettings));
    }
    
    protected void AddTriggers(QueryBuilder queryBuilder)
    {
        var triggers = AmbientDataHelper.GetTriggers();
        foreach(var kvp in triggers)
        {
            queryBuilder.AddCriteria(new CustomParameterCriteria(kvp.Key, kvp.Value));
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] regions = new[] { "Sidebar", "Header" };
        TcmUri _pageUri = new TcmUri("tcm:7-61-64");
        TcmUri _publicationUri = new TcmUri(0, _pageUri.PublicationId, 1);

        var queryBuilder = new QueryBuilder(_publicationUri, regions);
        AddTriggers(queryBuilder);

        Execute(queryBuilder);
    }
</script>

I hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.