Need to parse sections of meta data

Gold Contributor
Gold Contributor

We have the following i metadata:

 

<meta name="asset_topics" content="[{"sequence":"1","topic":{"topicId":"309","topicName":"Nutrition","topicTaxonomy":"Fitness and well-being/Food and nutrition/Nutrition"}}]" />

 

I want to set "topicTaxonomy" to a UDO variable.  Suggestions?  Thanks.

5 REPLIES 5

Need to parse sections of meta data

Employee Emeritus

Do you have jQuery loaded on your page @patrick_heavey?

Need to parse sections of meta data

Tealium Employee

First, define the meta data element in TiQ so that Tealium is aware of it - make sure type is "Meta Data Elements":

 

add data source

 

Also add a new UDO topic_taxonomy data source.

 

In a Set Data Values extension scoped to All Tags you can set the topic_taxonomy UDO variable to the parsed value setting the variable to js code (note the code text is truncated in the image below):

 

JSON.parse(b['meta.asset_topics'])[0].topic.topicTaxonomy 

 

Set data values

 

 

 

 

 

 

 

Note that this will generate an error if the asset_topics meta tag does not exist. If there will be cases where it won't exist on the page, you can check for its existence:

 

(typeof b['meta.asset_topics'] != 'undefined') ? JSON.parse(utag.data['meta.asset_topics'])[0].topic.topicTaxonomy : ''

 

 

 

If your utag.js version is >= 4.38 you have the option of having this extension running before load rules if needed.

Need to parse sections of meta data

Gold Contributor
Gold Contributor

Yes, we do.

Need to parse sections of meta data

Gold Contributor
Gold Contributor

Unfortunately this didn't seem to work - nothing's being passed. :manfrustrated:

Need to parse sections of meta data

Tealium Employee

@patrick_heavey 

 

The issue is that you have non-encoded double quotes within other double quotes in the meta tag. 

The meta tag content value is being read as "[{" becuase of the closing double quote.

 

 

To solve this you can use single quotes instead within the content value:

 

<meta name="asset_topics" content="[{sequence':'1','topic':{'topicId':'309','topicName':'Nutrition','topicTaxonomy':'Fitness and well-being/Food and nutrition/Nutrition'}}]" />

 

Note that this is not a Tealium issue. Search engines will stop at the second double quote as well. 

 

 

Public