4

I'm using DXA 1.5

I'm trying to output some values for Google Tag Manager's dataLayer. Some of these are required to be site wide.

The dataLayer is in the format

dataLayer = [{
    "name" : "value",
    "name2" : "value2" 
}];

I was thinking of adding a Google Tag Manager Configuration Component based on the General Configuration Schema which comes out of the box with DXA and then adding that to my module's configuration (or the Core configuration). So it will be published as json when I publish the Publish Settings Page.

So I'd like to be able to iterate over the Name Value Pair items in my General Configuration Component and output the names and the values to make the dataLayer script code.

However, I don't think I can actually get that Component specifically from the config as they are flattened into a single collection and accessed via Localization.GetConfigValue as far as I can see from the source.

This is no good to me as the key needs to be known in my View where I am writing out the code and I want to be able to add new items later without having to redploy the Views.

Does anyone know of a way of doing this before I write something custom?

I suppose I could publish the values as Taxonomy and access them via the CD API (I already have a service for that) but I'm interested if this is possible.

1 Answer 1

1

You can use a Component based on the DXA General Configuration Schema (key/value pairs) and map it to the Configuration View Model. That View Model has a single property (Settings) of type Dictionary<string,string>.

See: https://github.com/sdl/dxa-web-application-dotnet/blob/master/Sdl.Web.Common/Models/Entity/Configuration.cs

Note the SemanticProperty annotation used for Configuration.Settings; you can also use this on your own View Model to map all CM Fields to a single property.

1
  • Interesting, thanks Rick! I'll give that a try. Commented Oct 17, 2016 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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