that works similar to lodash _.get function, making it possible to obtain values from an object given a string (such as foo[0].bar).
- Open a Google Tag Manager web container and click into the Templates from the left sidebar menu.
- In the Variables Templates section, click on Search Gallery button.
- Click on the Search Icon then type "nested properties".
- Select the Nested Properties Object Getter template to your workspace.
- Use the new template as needed.
Input should be either an object or an array. You can enter a variable name such as {{ My Object }}. If the resolved value is undefined, the Default Value is returned in its place.
You can enter the path to retrieve using dots (foo.0.bar
) or using brackets (foo[0].bar
).
Can be either undefined
, empty string or a custom value. If custom value
is selected, you will be able to enter a custom string.
Source Object:
{
foo: [
{
bar: "GTM test 01"
},
{
bar: "GTM test 01"
}
]
}
Property Path: foo.0.bar
Returned Value: GTM test 01
Source Object:
{
foo: [
{
bar: "GTM test 01"
},
{
bar: "GTM test 01"
}
]
}
Property Path: foo[1].bar
Returned Value: GTM test 02
See our contributing guidelines.