Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google+ Snippet with Open Graph Protocol

I have a web page that is dynamically built and am trying to get links that are shared on Google+ to show snippets and look nice, an example snippet for article rendering and documentation can be found here:

https://developers.google.com/+/web/snippet/article-rendering

When I follow the documentation my links do not render with everything I set in google plus, they show up like this:

enter image description here

The head of my page looks like this:

<head>
<div id="replaceGoogle"></div>
</head>

In my javascript I have this to insert the open graph tags once generated:

//replace google
        var google = '<meta property="og:type" content="article" /><meta itemprop="og:headline" content="'+ data[0].name+'" /> <meta itemprop="og:description" content="View beer on Beer Portfolio" /> <meta property="og:image" content="'+ data[0].icon +'" />';
        $("#replaceGoogle").replaceWith(google);

The data is taken from json read in from an ajax call. Can I not do this dynamically?

like image 987
Mike Avatar asked Feb 23 '16 05:02

Mike


People also ask

Does Google use open graph protocol?

And Google don't use Open Graph Protocol in serp result. Open meta graph tags, help when you share your post in social media, so you can get more click through rate(CTR) by displaying rich content like images, or interesting headings.

What is Open Graph snippet?

Open Graph meta tags are snippets of code that control how URLs are displayed when shared on social media. They're part of Facebook's Open Graph protocol and are also used by other social media sites, including LinkedIn and Twitter (if Twitter Cards are absent).

Is Open Graph still used?

You can still use Open Graph tags with Twitter; the platform just implements its own tag system before Open Graph. However, Twitter cards have a requirement: images should be sized at 1024 pixels by 512 pixels.

What is Open Graph image URL?

Open Graph (OG) is a technology that social networks like Facebook, Twitter, Pinterest, etc., use to pull data from your site when you add a URL of your site in any of your posts on these services.


1 Answers

I think that question is similar to Generating Open Graph meta tags dynamically. The main reason of your problem is that google+ and facebook will not execute your javascript so none of them will see your dynamic og tags.

Basic solution to this problem is :

  • create unique url for each dynamic page and save dynamic params for this url into database.
  • when your user try to share pages with this unique url you will find saved dynamic params
  • create page with og tags filled with found dynamic params

Simple schema for saving og tags for dynamic generated pages

like image 151
alexander.polomodov Avatar answered Sep 27 '22 18:09

alexander.polomodov