All Projects → vinaygopinath → Ngmeta

vinaygopinath / Ngmeta

Licence: mit
Dynamic meta tags in your AngularJS single page application

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ngmeta

Laravelmetatags
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Stars: ✭ 226 (+48.68%)
Mutual labels:  opengraph, seo, meta-tags
Meta Tags
Search Engine Optimization (SEO) for Ruby on Rails applications.
Stars: ✭ 2,464 (+1521.05%)
Mutual labels:  opengraph, seo, meta-tags
Seotools
SEO Tools for Laravel
Stars: ✭ 2,406 (+1482.89%)
Mutual labels:  opengraph, seo, meta-tags
Fusebox Angular Universal Starter
Angular Universal seed project featuring Server-Side Rendering, @fuse-box bundling, material, firebase, Jest, Nightmare, and more
Stars: ✭ 132 (-13.16%)
Mutual labels:  seo, meta-tags, angularjs
The Seo Framework
The SEO Framework WordPress plugin.
Stars: ✭ 329 (+116.45%)
Mutual labels:  opengraph, seo
All In One Seo Pack
All in One SEO Pack plugin for WordPress SEO
Stars: ✭ 281 (+84.87%)
Mutual labels:  opengraph, seo
Rendora
dynamic server-side rendering using headless Chrome to effortlessly solve the SEO problem for modern javascript websites
Stars: ✭ 1,853 (+1119.08%)
Mutual labels:  crawler, seo
Yoast Seo For Typo3
Yoast SEO plugin for TYPO3
Stars: ✭ 43 (-71.71%)
Mutual labels:  opengraph, seo
laravel-assets
Laravel Assets manager
Stars: ✭ 13 (-91.45%)
Mutual labels:  seo, meta-tags
Ultimate Metatags
A large snippet for your page's <head> that includes all the meta tags you'll need for OPTIMAL sharing and SEO. Extensive work has been put into ensuring you have the optimal images for the most important social media platforms.
Stars: ✭ 24 (-84.21%)
Mutual labels:  opengraph, meta-tags
Angular Metatags
Module for providing dynamic Meta Tags to Angular routes
Stars: ✭ 62 (-59.21%)
Mutual labels:  seo, meta-tags
Sitemap Generator
Easily create XML sitemaps for your website.
Stars: ✭ 273 (+79.61%)
Mutual labels:  crawler, seo
spiderable-middleware
🤖 Prerendering for JavaScript powered websites. Great solution for PWAs (Progressive Web Apps), SPAs (Single Page Applications), and other websites based on top of front-end JavaScript frameworks
Stars: ✭ 29 (-80.92%)
Mutual labels:  crawler, seo
Ngx Meta
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
Stars: ✭ 331 (+117.76%)
Mutual labels:  seo, meta-tags
wagtail-metadata-mixin
🔍 OpenGraph, Twitter Card and Schema.org snippet tags for Wagtail CMS pages
Stars: ✭ 42 (-72.37%)
Mutual labels:  seo, opengraph
Head
A simple guide to HTML <head> elements
Stars: ✭ 28,892 (+18907.89%)
Mutual labels:  seo, meta-tags
Laravel Seo Tools
Laravel Seo package for Content writer/admin/web master who do not know programming but want to edit/update SEO tags from dashboard
Stars: ✭ 99 (-34.87%)
Mutual labels:  seo, meta-tags
Scrapoxy
Scrapoxy hides your scraper behind a cloud. It starts a pool of proxies to send your requests. Now, you can crawl without thinking about blacklisting!
Stars: ✭ 1,322 (+769.74%)
Mutual labels:  crawler, angularjs
Magento 2 Seo
Magento 2 SEO extension will do perfectly for your better SEO. This is a bundle of outstanding features that are auto-active when you install it from Mageplaza without any code modifications. It is also friendly with your store if you need to insert meta keywords and meta descriptions for your product.
Stars: ✭ 99 (-34.87%)
Mutual labels:  seo, meta-tags
magento2-module-seo
Magento 2 Module for Search Engine Optimization
Stars: ✭ 100 (-34.21%)
Mutual labels:  seo, opengraph

ngMeta

Dynamic meta tags in your AngularJS single page application

npm version Build Status Join the chat at https://gitter.im/ngMeta/Lobby

This is an Angular 1.x module. Angular2 module is available as ng2-meta

Demo

vinaygopinath.github.io/ngMeta

Install

via NPM:

npm install ng-meta --save

via Bower:

bower install ngMeta --save

via CDN:

https://cdnjs.cloudflare.com/ajax/libs/ng-meta/1.0.3/ngMeta.min.js

or download the file from dist.

Getting started

  1. Add ngMeta as a dependency of your module. ngMeta supports ui-router and ngRoute.

    angular.module('YourApp',['ngMeta']);
    
  2. Add meta objects to your routes (ngRoute) or states (ui-router) and specify the meta tags appropriate to each view. Other than title and titleSuffix, which are reserved properties that affect the title of the page, the tag properties can be named as per your choice.

    .config(function ($routeProvider, ngMetaProvider) {
    
      $routeProvider
      .when('/home', {
        templateUrl: 'home-template.html',
        data: {
          meta: {
            'title': 'Home page',
            'description': 'This is the description shown in Google search results'
          }
        }
      })
      .when('/login', {
        templateUrl: 'login-template.html',
        data: {
          meta: {
            'title': 'Login page',
            'titleSuffix': ' | Login to YourSiteName',
            'description': 'Login to the site'
          }
        }
      });
      ...
    });
    
  3. [Optional] Set the default values of meta tags during Angular's configuration phase. If the meta object of a route does not contain a specific tag, the default value is used instead.

    //Add a suffix to all page titles
    ngMetaProvider.useTitleSuffix(true);
    
    // On /home, the title would change to
    // 'Home Page | Best Website on the Internet!'
    ngMetaProvider.setDefaultTitleSuffix(' | Best Website on the Internet!');
    
    //Set defaults for arbitrary tags
    // Default author name
    ngMetaProvider.setDefaultTag('author', 'John Smith');
    
  4. Let ngMeta initialize by calling the init() function in the app.js run block

    angular.module('YourApp', ['ngRoute', 'ngMeta'])
    .config(function($routeProvider, ngMetaProvider) {
      ....
    })
    .run(['ngMeta', function(ngMeta) {
      ngMeta.init();
    }]);
    
  5. Set the meta tags in your HTML file

    <title ng-bind="ngMeta.title"></title>
    
    <!-- Arbitrary tags -->
    <meta property="og:type" content="{{ngMeta['og:type']}}" />
    <meta property="og:locale" content="{{ngMeta['og:locale']}}" />
    <meta name="author" content="{{ngMeta['author']}}" />
    <!-- OR <meta name="author" content="{{ngMeta.author}}" /> -->
    <meta name="description" content="{{ngMeta.description}}" />
    

Defaults

Change app-wide behaviour and set default values to tags using these methods of ngMetaProvider. These defaults can be overridden by defining equivalent properties in the route/state meta object

angular.module('YourApp', [....,'ngMeta'])
.config(function(ngMetaProvider) {

	ngMetaProvider.useTitleSuffix(true);
    ngMetaProvider.setDefaultTitle('Fallback Title');
    ngMetaProvider.setDefaultTitleSuffix(' | YourSite');
    ngMetaProvider.setDefaultTag('author', 'John Smith');
});
Method Default Example
useTitleSuffix(boolean)
Toggles the use of a title suffix. When enabled, the title suffix of the route (if available) or the default title suffix is appended to the title of all pages.
false ngMetaProvider.useTitleSuffix(true);
setDefaultTitle(String)
Sets the default title for all routes. This serves as a fallback for routes that don't have a title property. Use this to customize titles for a few specific routes, letting other routes use the default title.
undefined ngMetaProvider.setDefaultTitle('Spotify');
ngMetaProvider.setDefaultTitle('Generic Title');
setDefaultTitleSuffix(String)
Sets the default title suffix for all routes. This serves as a fallback for routes that don't have a titleSuffix property. The default title suffix is relevant only when useTitleSuffix is set to true.
undefined ngMetaProvider.setDefaultTitleSuffix(' - Site Name');
ngMetaProvider.setDefaultTitleSuffix(' - YourSite');
setDefaultTag(String, String)
Sets the default value of any arbitrary tag. This serves as a fallback for routes that don't have a particular tag.
N/A ngMetaProvider.setDefaultTag('author', 'John Smith');
ngMetaProvider.setDefaultTag('ogImgUrl', 'http://example.com/img.png');

Dynamic meta tags

To change meta tags dynamically (when an item in a list is clicked, for example), inject the ngMeta service into your controller and use one of the following methods:

angular.module('YourApp')
.controller(function(ngMeta) {
  //These examples assume useTitleSuffix is enabled,
  //and default titleSuffix is set to 'Playlist'

  //Custom title and titleSuffix
  ngMeta.setTitle('Eluvium', ' | Spotify'); //Title = Eluvium | Spotify
  //default titleSuffix
  ngMeta.setTitle('Eluvium'); //Title = Eluvium | Playlist
  //Clear the default titleSuffix
  ngMeta.setTitle('Eluvium',''); //Title = Eluvium

  ngMeta.setTag('author', 'Matthew Cooper');
  ngMeta.setTag('image', 'http://placeholder.com/abc.jpg');

  ngMeta.setDefaultTag('author', 'Default author');
  //Set default tags (non-default tags, like author and image above, are NOT cleared)
  ngMeta.resetMeta();
});

Note: Please use setTitle to modify the title and/or titleSuffix and setTag for all other tags.

Method Description Example
setTitle(String title, String titleSuffix) Sets the current title based on the given params. When useTitleSuffix is enabled and titleSuffix is not provided, it uses the default titleSuffix. ngMeta.setTitle('Title', ' - TitleSuffix')

ngMeta.setTitle('Title with default titleSuffix')

ngMeta.setTitle('Title with no titleSuffix','')
setTag(String tagName, String value) Sets the value of an arbitrary tag, using the default value of the tag when the second param is missing. The value is accessible as {{ngMeta.tagName}} from HTML. Calling setTag with title or titleSuffix as tagName results in an error. Title must be modified using setTitle instead. ngMeta.setTag('author', 'John Smith')

ngMeta.setTag('ogImage', 'http://url.com/image.png')
setDefaultTag(String tagName, String value) Sets the default value of an arbitrary tag, overwriting previously set default values, but not the value set dynamically (using setTitle/setTag) or by the route/state. title and titleSuffix are accepted values. ngMeta.setDefaultTag('image', 'http://default-image-url.com');

ngMeta.setDefaultTag('title','Default title');
resetMeta(void) Applies the default meta tags. This is relevant when using ui-router and disableUpdate: true (Refer this comment). Custom tags set dynamically (using setTag or setTitle) are not cleared. ngMeta.resetMeta();

Debugging

  • ng-inspector Chrome extension shows the tags set by ngMeta when a state/route is open ng-inspector running on an Angular SPA with ngMeta

  • Facebook's Open Graph Object Debugger shows detailed information about your site's meta tags as well as a preview of the snippet shown when your site is shared. Note that you need to use server-side rendering or prerendering in combination with ngMeta to see your meta tags in the the debugger

Advanced

Data inheritance in ui-router

If you wish to take advantage of nested views and data inheritence, then you should specify your meta config underneath the data property like this:

$stateProvider
  .state('services', {
    abstract: true,
    url: '/services',
    templateUrl: '/services/base.html',
    controller: 'servicesCtrl',
    data: {
      'meta': {
        'og:image': 'http://www.yourdomain.com/img/facebookimage.jpg',
        'author': 'PawSquad'
      }
    }
  })
  .state('services.vaccinations', {
    url: '/vaccinations',
    templateUrl: '/services/vaccinations.html',
    controller: '',
    data: {
      'meta': {
        'title': 'Pet Vaccinations - All You Need To Know | PawSquad',
        'og:title': 'All You Need To Know About Pet Vaccinations',
        'og:description': 'Useful information about Routine Vaccines and Boosters for dogs and cats,   including start vaccines for puppies and kittens.',
      }
    }
  })

Furthermore, you should use the helper function to decorate $stateProvider's data function like this

.config(['ngMetaProvider', function (ngMetaProvider) {
  $stateProvider.decorator('data', ngMetaProvider.mergeNestedStateData);
}])

In this way the metadata for the /services/vaccinations URL would be

  'meta': {
    'og:image': 'http://www.yourdomain.com/img/facebookimage.jpg',
    'author': 'PawSquad',
    'title': 'Pet Vaccinations - All You Need To Know | PawSquad',
    'og:title': 'All You Need To Know About Pet Vaccinations',
    'og:description': 'Useful information about Routine Vaccines and Boosters for dogs and cats, including start vaccines for puppies and kittens.'
  }

Using custom data resolved by ui-router

If you want to dynamically set your tags using ui-router's resolve, this is possible as well:

resolve: {
  data: function(..., ngMeta) {
    //Ex: Load data from HTTP endpoint
    ....
    ngMeta.setTitle();
    ngMeta.setTag('description', '....');
    ngMeta.setTag('image', '....');
  }
},
meta: {
  disableUpdate: true
}

The property disableUpdate: true is required because ui-router will execute the resolve function before the $stateChangeSuccess event is fired. Setting disableUpdate: true will prevent your tags from getting reset by the $stateChangeSuccess event listener.

Support for other crawlers

While Google is capable of rendering Angular sites, other search engines (?) and crawler bots used by social media platforms do not execute Javascript. This affects the site snippets generated by sites like Facebook and Twitter. They may show a snippet like this one:

Facebook site snippet

You can use prerendering services to avoid this issue altogether, or update the server config to generate and serve a simplified page with just the open graph meta data needed for the bots to create snippets. Michael Bromley's article, Enable Rich Sharing In Your AngularJS App has more information on how to do that.

TL;DR: ngMeta helps the Google crawler render your Angular site and read the meta tags. For other sites like Facebook/Twitter that can't render Javascript, you need to use pre-renderers or server redirects.

Websites using ngMeta

  • acloud.guru - AWS certification online learning platform

To list your website here, please make a PR (or edit README.md on GitHub) and add your URL in this section of README.md in this format

"Site URL - Short description"

Further reading

MIT Licence

Vinay Gopinath

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].