Implementing the Open Graph Protocol

Since the Open Graph protocol uses a simple implementation based on metadata, incorporating it into your site is fairly straightforward and requires only some <meta> tags—the exact number depending on how much data you are looking to expose—in the <head> of your web pages.

Since this is a simple format, the main things we’ll explore in this technology have to do with what information you can expose and how to expose it. The potential data you can expose can be broken up into page metadata, geographic information, contact information, and object types. Let’s explore what these tags look like.

Defining page metadata

Page metadata is the foundation for transforming a web page into a rich data object in a user’s social graph. The Open Graph protocol defines a number of metadata properties that are required for implementation. These are listed in Table 10-1.

Table 10-1. Required page metadata properties

Property

Description

og:image

An image to be associated with the object, such as a thumbnail or screenshot.

og:title

A title describing the site object, much like using the standard HTML <title> tag.

og:type

The type of object being represented on the page, such as a sports team or business.

og:url

The URL to the information page for the object.

Let’s look at a practical example of how metadata is represented on a Yelp product review page for the Restaurant at Wente Vineyards in Livermore, CA:

<html xmlns:og="http://ogp.me/ns#">
<head>
<title>The Restaurant at Wente Vineyards - Livermore, CA</title>
<meta property="og:url" content="http://www.yelp.com/biz/gATFcGOL-q0tqm9HTaXJpg">
<meta property="og:type" content="restaurant">
<meta property="og:title" content="The Restaurant at Wente Vineyards">
<meta property="og:image"
      content="http://media2.px.yelpcdn.com/bphoto/iVSnIDCj-fWiPffHHkUVsQ/m">
...
</head>
...
</html>

In addition to the required tags, there are several tags whose implementation is optional but recommended for any site. These are listed in Table 10-2.

Table 10-2. Optional page metadata properties

Property

Description

og:description

An arbitrary description (which could be several sentences long) of the object being represented on the site.

og:site_name

The root site that the page is associated with. For instance, a single movie page on IMDb.com would set the content of the og:site_name <meta> tag to IMDb.

Let’s go back to our previous Yelp example. Should Yelp wish to extend that review with the additional metadata properties from Table 10-2, it might look like this:

<meta property="og:site_name" content="Yelp">
<meta property="og:description" content="The award winning Restaurant at Wente
   Vineyards is truly a feast for the senses! The open architecture is inviting
   and the air alive with rich, savory aromas.">

Specifying Yelp as our site name indicates that this page is a small piece of the overall entity graph that is Yelp.com, comprising many reviews. The site_name offers a link to the richer social graph, and the description provides more detail about a page.

Specifying geolocation data

The Open Graph protocol supports the ability to define geographical information within the metadata tags. This is a valuable option for any site that is representing something with a real-world location, such as the restaurant we just looked at in the Yelp example.

There are a number of properties available for defining geographical information, from address information to latitude and longitude. These are specified in Table 10-3.

Table 10-3. Geolocation properties

Property

Description

og:country-name

The country name associated with the real-world object.

og:latitude

The geographical latitude of the real-world location represented on the page.

og:locality

The city/town/village associated with the real-world object.

og:longitude

The geographical longitude of the real-world location represented on the page.

og:postal-code

The postal or zip code associated with the real-world location.

og:region

The state or province associated with the real-world location.

og:street-address

A free-form text address associated with the real-world location.

Going back to our previous Yelp example, let’s extend the page metadata tags with our new geographical information:

<html xmlns:og="http://ogp.me/ns#">
<head>
<!-- INSERT: Required OGP Tags -->
<meta property="og:latitude" content="37.6246361">
<meta property="og:longitude" content="-121.7567068">
<meta property="og:street-address" content="5050 Arroyo Rd" />
<meta property="og:locality" content="Livermore" />
<meta property="og:region" content="CA" />
<meta property="og:postal-code" content="94550" />
<meta property="og:country-name" content="USA" />
...
</head>
...
</html>

These tags are tremendously valuable for any site that represents a physical location, such as a business. It not only provides immediate address information, but it also integrates latitude and longitude coordinates that can be used to plot locations on mapping products or provide directions from a viewer’s current location.

Specifying contact information

Taking the available metadata even further, let’s assume that you are a business owner or that you provide some type of content where you want people to be able to contact you or your company. This is where contact <meta> tags come into play.

Using these tags (shown in Table 10-4), a site owner can include main contact information that people viewing the site can use.

Table 10-4. Contact properties

Property

Description

og:email

A contact email address for the business or site. Since this information is made publicly available, you should always use a dedicated email address for only the site in question.

og:fax_number

A contact fax number for the business or site.

og:phone_number

A contact phone number for the business or site.

If we expand even further on our previous Yelp restaurant review page to now include contact information, the new section may look something like this:

<html xmlns:og="http://ogp.me/ns#">
<head>
<!-- INSERT: Required OGP Tags -->
<meta property="og:email" content="[email protected]" />
<meta property="og:fax_number" content="925-456-2301" />
<meta property="og:phone_number" content="925-456-2300" />
...
</head>
...
</html>

Implementing contact information in conjunction with geographic data can provide enough data for any site to define a profile page for your business, such as how Yelp supplements its data with business contact information and an associated map to show the location.

Attaching video data

If you want to attach video data on your page and have it reflected in the Open Graph protocol metadata, you’ll employ the og:video tag and its children.

There are a number of tags available for specifying a video file, as shown in Table 10-5.

Table 10-5. Video properties

Property

Description

og:video

The URL to the video file that you have embedded on the page.

og:video:height (optional)

The height of the video in pixels.

og:video:type (optional)

The MIME type for the video. If no type is specified, the parser should attempt to infer the type. The Open Graph protocol suggests using a default of application/x-shockwave-flash until HTML5 video is more common.

og:video:width (optional)

The width of the video, in pixels.

If we look at what these features look like as <meta> tags, we can see the implementation potential:

<html xmlns:og="http://ogp.me/ns#">
<head>
<!-- INSERT: Required OGP Tags -->
<meta property="og:video" content="http://www.example.com/keyboardcat.flv" />
<meta property="og:video:height" content="450" />
<meta property="og:video:width" content="550" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
...
</head>
...
</html>

Using video metatagging for individual pages can help to surface videos underneath a root site, helping site viewers more easily discover its video content.

Attaching audio data

Much like the og:video tag, og:audio allows a site promoting audio content to tag information about the music being played on a particular page. Table 10-6 lists the available tags.

Table 10-6. Audio properties

Property

Description

og:audio

The absolute URL to the audio track being presented.

og:audio:album (optional)

The album name.

og:audio:artist (optional)

The artist name.

og:audio:title (optional)

The audio track title.

og:audio:type (optional)

The MIME type of the audio track. If no type is specified, the parser should attempt to infer the type.

Here’s how these <meta> tags look in context:

<html xmlns:og="http://ogp.me/ns#">
<head>
<!-- INSERT: Required OGP Tags -->
<meta property="og:audio" content="http://www.example.com/song.mp3" />
<meta property="og:audio:album" content="My amazing album" />
<meta property="og:audio:title" content="The greatest song ever" />
<meta property="og:audio:artist" content="The best band" />
<meta property="og:audio:type" content="application/mp3" />
...
</head>
...
</html>

Implementing tagging for individual audio tracks on pages provides the same benefits as it does for video tags. You are able to surface individual pages more readily to individuals who are searching your content and provide them with the general information they need to get an idea of what is offered on your site.

Defining products using object types

Every element in an entity social graph is by definition a type of object. At a base level, that’s all an entity is—an object describing the user interaction and any relevant information about it.

Defining an object type within the Open Graph protocol adds the entity to a specific section of the site (i.e., organizes the site by category). You define an object type using the following syntax:

<meta property="og:type" content="activity" />

The property value remains og:type, but you’ll change the content value to whatever object type best defines the page. The types can be further grouped into individual categories. For example, the first category we’ll look at, activities, should be used when the page content relates to sporting events, outings, physical activities, conferences, or the like.

Activities

activity

sport

 

The next category, businesses, encompasses sites that contain information about companies, such as restaurants, company websites, or any other business presence on the Web.

Businesses

bar

café

restaurant

company

hotel

 

Use group types when delivering content to people who are interested in specific sporting information or certain causes. Pages that might include these object types are football, baseball, or hockey team or league sites; sites that are attempting to gain community support for causes or events, such as marches for cancer; and rally or protest sites.

Groups

cause

sports_league

sports_team

Organization object types are intended for groups that are not included under businesses, such as schools, nonprofits, and federal or local government sites.

Organizations

band

non_profit

university

government

school

 

If the site content is devoted to a specific person, using the people object types will ensure that the site is placed in the appropriate category within the graph. This category may include fan pages, sites including biographical data for individuals, or campaign sites for political candidates.

People

actor

director

politician

athlete

musician

public_figure

Place objects target pages that contain geographical, map, or location-based data. This may include landmarks such as the Statue of Liberty, city informational websites, or sites that provide information on specific countries.

Places

city

country

landmark

Products and entertainment objects cover a number of the remaining page attributes and include items like books, movie sites, and TV shows. Should the product page include a UPC or ISBN, you may use the og:upc or og:isbn object types to better specify the page content.

Products and entertainment

album

food

product

book

game

song

drink

movie

tv_show

Finally, the websites group is used to denote many social media outreach channels that do not fit into the products and entertainment category. These include articles, blogs, and generic websites. The website type can be used as a generic attribute for sites that do not fit in above categories.

Websites

article

blog

website

Using this extensive list of object types, you can specify the kind of information contained within your page, properly categorizing the elements of a user’s online entity graph and thus providing a rich extension to the standard definition of a social graph.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.68