Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

og meta tags, social buttons and angularjs

I'm creating a website using multiple views. The tag and the tags of the page get changed through a a $rootScope variable. so I have something like

<html>
<head>
   <title ng-bind="page_title"></title>
   <meta property="og:title" content="{{page_title}}">
</head>

Whenever each view get loaded on the website, the page_title variable changes and the title and the og:title tags get updated (everything works as expected).

The problem is that I need, on some views to load a facebook, a google+ and a twitter button. I can display them properly but if I click on each them the page title appear to be something like:

{{page_title}}

I've tried to delay the execution of the scripts of each button using setTimeOut but to no good. But the scripts just read whatever is written, they don't parse the page_title.

Does anyone know a workaround to this?

Thank you

like image 788
Terumi Avatar asked Jun 15 '13 21:06

Terumi


People also ask

What are social meta tags?

Social meta tags allow website owners to have some control over what content shows up when a web page is shared on social media platforms (Facebook, Twitter, LinkedIn, etc.). Social meta tags, also commonly referred to as open graph meta tags, rely on the Open Graph Protocol.

What is OG tag in HTML?

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). You can find them in the <head> section of a webpage.

What is meta tag in angular?

Meta tags are simply a small amount of HTML code that is used to describe the content of your web page. Meta tags provide metadata about the HTML document and are typically used to provide information about webpage content, author, keywords, viewport settings, etc.

What is FB meta tag?

You can optionally set metadata tags in your product feed files. This enables Facebook to attribute catalogs using this feed to your app. Once a catalog is attributed to your app, the meta tag is not required in subsequent feed uploads to that catalog.


1 Answers

This can't be done using javascript. Some people think that Facebook is reading what's currently on the page. It's not. It makes a separate request to your server using the same url (from window.location.href) using it's Scraper, and the Facebook Scraper does not run javascript. That's why you get {{page_title}} when clicking on something like a Facebook share button. Your content will have to be generated by the server so when Facebook goes to hit the url it gets the content it needs up front without the need for javascript. You can tackle the server side rendering in a fews ways.

  1. You can allow your server side technology to render the content.
  2. You can use the PhantomJS approach https://github.com/steeve/angular-seo.
like image 119
Earl Ferguson Avatar answered Sep 27 '22 20:09

Earl Ferguson