# Metadata for ads configuration

Metadata from articles or sections can be used in the inventory.json to fulfill the ad placements configuration.

This is an example of two metedata in the Tenant's site:

<script class="mrf-adTargetings" type="application/ld+json">
  {@context":"http://schema.org","@type":"AdTArgetings","ad Targetings":
  {"path":"/1234/ex.ample/section","cats":"example category","slug":"example-slug","contenttype":"handmade"}}
</script>
<script class="mrf-gaCustomVariables" type="application/ld+json">
  {"@context":"http://schema.org","@type":"GACustomVariables","customVar": {"1": {"index":
  "1","name": "PageType","value": "sports","scope": ""},"4": {"index": "4","name":
  "UserSegment","value": "Anonymous","scope": ""},"2": {"index": "2","name":
  "TopNode","value": "sports","scope": ""}}}
</script>

From this, we'd have the following json:

{
  "AdTargetings": {
    "@context": "http://schema.org",
    "@type": "AdTargetings",
    "adTargetings": {
      "path": "/1234/ex.ample/example-url",
      "cats": "example category-1234",
      "slug": "example-url",
      "contenttype": "handmade"
    }
  },

  "GACustomVariables": {
    "@context": "http://schema.org",
    "@type": "GACustomVariables",
    "customVar": {
      "1": {
        "index": "1",
        "name": "PageType",
        "value": "sports",
        "scope": ""
      },
      "4": {
        "index": "4",
        "name": "UserSegment",
        "value": "Anonymous",
        "scope": ""
      },
      "2": {
        "index": "2",
        "name": "TopNode",
        "value": "sports",
        "scope": ""
      }
    }
  }
}

To use any metadata in inventory.json, it's necessary to create a placeholder like the following in the params of the ad placement:

${metadatas.NAME_OF_METADATA_.REST_OF_FIELDS_WE_WANT}

For example:

  • ${metadatas.AdTargetings.adTargetings.path}
  • ${metadatas.GACustomVariables.customVar}
  • ${metadatas.AdTargetings.adTargetings.slug}

Example in an inventory.json:






 











{
    "placements": {
        "inline": {
            "adServer": "dfp",
            "params": {
                "END_SLOT": "${metadatas.AdTargetings.adTargetings.path}"
            }
        }
    },
    "adServers": {
        "dfp": {
            "type": "doubleclick",
            "slot": "/55115104/marfeelTag_AMP${END_SLOT}",
        }
    }
}

# Custom value of a metadata value

For this example, suppose that we just want the "/WHAT_I_WANT/" part from the path:

{
    "NICE_METADATA": {
        "adTargetings": {
            "path": "/5856/WHAT_I_WANT/are-we-there-yet"
        }
}

In this case, you would need to modify the metadata providers to create the object with the values you need.

# Accessing arrays in metadata

When using metadata, the syntax to access a property that is inside an array is:

metadatas.metadataName.(arrayField)[arrayIndex].anyProperty

For example:

{
  "AdTargetings": {
    "@context": "http://schema.org",
    "@type": "AdTargetings",
    "smartConfig": [
      {
        "networkid": 1234,
        "domain": "//www8.smartadserver.com",
        "async": true,
        "siteId": 123456,
        "pageId": 123456,
        "formatId": "55555,55555,55555,55555,55555,55555,55555,55555",
        "target": "cat1=53;|width=undefined;height=undefined"
      }
    ]
  }
}

As you can see, the field smartConfig is an array of objects.

If we needed the field target, we would need to do:

"${metadatas.AdTargetings.(smartConfig)[0].target}"

TIP

Notice the parenthesis and the index in the array.