I have a clean instance of SDL Web 8 with DXA v2.0 and am using the new R2 data model.

I want to expose Target Group Conditions in the JSON generated by the DXA R2 TBBs but I am not having much success.

I have updated the RenderComponentContent and RenderPageContent TBBs to include the AddTargetGroupsModelBuilder model builder as the last item in the modelBuilderTypeNames pipeline although based on the source code I think it should only be needed in the RenderComponentContent TBB.

See: https://github.com/sdl/dxa-content-management/blob/release/2.0/Sdl.Web.Tridion.Templates.R2/Data/TargetGroups/AddTargetGroupsModelBuilder.cs

Despite adding this TBB and checking Target Groups for a given page, I do not see anything in the JSON that represents the serialized data in the output.

Am I missing any obvious steps here? Happy to provide more verbose detail on request.

  • Have you tried debugging a Page in Template Builder with Log Level set to Debug? Do you see the message logged by AddTargetGroupModelBuilder? – Rick Pannekoek Jun 27 '18 at 18:33
  • Hi @RickPannekoek, I did debug in Template Builder and see the following statements: AddTargetGroupsModelBuilder: AddTargetGroupsModelBuilder initialized. DataModelBuilderPipeline: Using Entity Model Builder type 'Sdl.Web.Tridion.Templates.R2.Data.AddTargetGroupsModelBuilder'. AddTargetGroupsModelBuilder: Adding target groups to entity model data. That suggests that the model builder executed but I don't see anything in the generated JSON. – John Askew Jun 27 '18 at 18:40
  • Unfortunately, there are quite a few paths where the model builder can silently not do anything after logging that message. You may have to attach a debugger to see what happens exactly. – Rick Pannekoek Jun 27 '18 at 20:24

It will only generate tags if you Create a Target Group and then Add Target group with a component presentation on the page.

AddTargetGroupsModelBuilder should be updated in RenderPageContent TBBs

JSON output looks like this:

"ExtensionData": {
            "TargetGroupConditions": {
              "$type": "Condition[]",
              "$values": [
                  "$type": "CustomerCharacteristicCondition",
                  "Name": "member",
                  "Operator": 0,
                  "Value": "10",
                  "Negate": false

To read more about this how to create a target group and associate, have a look at the documentation "Target Groups"

I hope it helps.

| improve this answer | |
  • Hi @Velmurugan, I had created multiple Target Groups and checked them against various component presentations on the page. I can see this reflected in the Page package item but not the JSON in the package Output item. – John Askew Jun 28 '18 at 15:39
  • I did use CustomerCharacteristicCondition to test, it works for me, what is the condition did you use to add? – Velmurugan Jun 28 '18 at 18:37
  • I was testing with CustomerCharacteristicCondition too. I'm going to have to attach a debugger and build the source locally to properly debug this. I'm confident that my CM setup is correct. – John Askew Jun 29 '18 at 18:43

It works!

I don't know what changed. I deleted and re-created the Target Groups, re-published the page, and huzzah - the extension data is present in the json.

Thanks to all those who commented and responded.

| improve this answer | |

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.