Code Monkey home page Code Monkey logo

apostrophe-seo's Introduction

CircleCI

apostrophe-seo

SEO configuration for ApostropheCMS.

Add useful meta fields to all pages and pieces.

Installation

npm install apostrophe-seo --save

Use

1. Initialization

Configure apostrophe-seo in app.js.

const apos = require('apostrophe')({
  shortName: 'project',
  modules: {
    'apostrophe-seo': {}
  }
});

Setting the baseUrl

It is important to set the baseUrl option on your ApostropheCMS application for various reasons. In the SEO module it contributes to building the correct canonical link tag URL and allows to access the SEO page scan modal. This can be set on the main app configuration in app.js (statically or with an environment variable) or in the data/local.js file as that file will contain environment/server-specific configurations.

// in app.js
require('apostrophe')({
  shortName: 'my-project-name',
  baseUrl: 'https://myproject.com' // OR process.env.BASE_URL
  modules: { ... },
}
// in data/local.js
module.exports = {
  baseUrl: 'https://example.com'
  // or set to `http://localhost:3000` during development on your local machine.
};

2. Module configuration

If you choose to disable fields for a piece or page you can do so by setting seo: false on the module. apostrophe-files, apostrophe-global, apostrophe-groups, apostrophe-images, apostrophe-users have seo: false configured by default.

module.exports = {
  name: 'person',
  label: 'Person',
  pluralLabel: 'People',
  seo: false
};

Adding global fields for analytics

If you would like to configure additional fields to allow an editor to add a Google Analytics tracking ID and a Google site verification ID you can do so by setting seoGoogleFields: true in apostrophe-global in your project. Add seoGoogleTagManager: true to also add a field for the Google Tag Manager ID (seoGoogleFields must also be true in this case).

Finally, you may only want to use Google Tag Manager for all analytics and site verification needs. Set seoTagMangerOnly: true in apostrophe-global to do this. Doing so will override the other options, making their presence irrelevant if also set.

Setting rules for SEO page scanner

You can access a SEO page scanner through the page menu, it allows you to process seo related verifications on the current page. If you are using apostrophe-workflow, notice that the button is accessible in draft and live modes. Also, keep in mind that, when accessing the modal, your current url must match the baseUrl flag set in the project. Otherwise the server will not return the modal.

Some of the rules can be configured from your apostrophe-seo declaration.

If you need authentication to access your website, you can also pass headers to the config.

  'apostrophe-seo': {
    scanRules: {
      titleLength: {
        min: 40,
        max: 80
      },
      descriptionLength: {
        min: 40,
        max: 80
      },
      ogTitleLength: {
        min: 40,
        max: 80
      },
      ogDescriptionLength: {
        min: 40,
        max: 80
      },
      minWordsOnPage: 400
    },
    scanHeaders: {
      // Passing some headers if necessary
    }
  }

You can choose the desired length for meta title and description, as well as for open graph title and description. You also can choose the minimum of words you want in a page. If you don't, some default values are used.

3. Updating views

Add the following include to your <head></head> in layout.html that all of your pages extend, or to outerLayout.html if you have one in apostrophe-templates/views/. This will output the meta tags needed for SEO and Google Analytics/Verification configuration.

{% if data.piece %}
  {% if data.piece.seoTitle %}
    {% set title = data.piece.seoTitle %}
  {% else %}
    {% set title = data.piece.title %}
  {% endif %}
{% else %}
  {% if data.page.seoTitle %}
    {% set title = data.page.seoTitle %}
  {% else %}
    {% set title = data.page.title %}
  {% endif %}
{% endif %}

{% block title %}{{ title }}{% endblock %}

{% block extraHead %}
  {% include "apostrophe-seo:view.html" %}
{% endblock %}

The canonical link field on a page or piece allows an editor to select another page that search engines should understand to be the primary version of that page or piece. As described on Moz.com:

A canonical tag (aka "rel canonical") is a way of telling search engines that a specific URL represents the master copy of a page. Using the canonical tag prevents problems caused by identical or "duplicate" content appearing on multiple URLs. Practically speaking, the canonical tag tells search engines which version of a URL you want to appear in search results.

Optionally add the following include to your notFound.html view. If the app has a Google Tracking ID value entered, this will send an event to Google Analytics tracking the 404 response, the URL on which it happened, and, if applicable, the page on which the bad URL was triggered (helping you identify where bad links are located).

{% block extraBody %}
  {{ super() }}
  {% include "apostrophe-seo:notFound.html" %}
{% endblock %}

If you already have an extraBody block in the notFound.html view file, you'll only need to add the {% include "apostrophe-seo:notFound.html" %} statement somewhere in that.

SEO Page Scan

You can access the SEO page scan modal from pages menu. It performs a SEO scan of the current page to verify that good practices are respected. It checks that meta title, description, open graph title and description are all existing, unique and the right length (that you can configure as explained above). It also checks that you have only one <h1> on the page. Finally it allows you to perform scans for links and images. For links, it checks that no links lead to 404 responses. To do this, it requests all internal links from the browser, and send external links to a specific route which will request them. For images, It checks, for the current page, that every <img> tag has an alt attribute. If some are not, It displays them with the appropriate message. If the alt attribute exists but is empty it only warns you and displays images too. By default only admins can use the SEO Page Scan button, however you can assign the SEO Page Scan permission to other Apostrophe groups.

apostrophe-seo's People

Contributors

abea avatar austinstarin avatar bodonkey avatar boutell avatar gregvanbrug avatar haroun avatar valjed avatar woodbrearlham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apostrophe-seo's Issues

Environment specific Google Analytics IDs and/or Google Tag Manager IDs

The problem to solve

We like to test Google Tag Manager configurations in our dev/test environments (in conjunction with a GTM test container and test GA Property) prior to implementing in our production site.

Currently enabling Google Fields via the seoGoogleFields: true directive enables the fields becoming available in the Global menu option, meaning that they are stored in the database. Any synching of the database between environments will overwrite alternate configs in the target environment, risking polluting production analytics with development data (when the production IDs get used in a dev setting), and require a manual intervention to update with the correct IDs.

Proposed solution

Providing overrides in the local.js, a la baseURL and similar settings, to configure the appropriate Google IDs rather then using manually configured settings via the Admin menu tab.

Alternatives

Manual maintenance of environments.

Google tracking ID label might be misleading

'Tracking ID provided by Google for Google Analytics.'

This then goes to a Google Tag Manager snippet, but it sounds like the traditional Google Analytics. I'd suggest either we include both options (the dev would choose one to expose) or change the label here to specify Google Tag Manager.

CC @austinstarin @bgantick @arti5m @mtthwmnc

The example is wrong

The example in README.md is wrong,
If you put the {% block title %}{{ title }}{% endblock %} in {% block extraHead %}, you will see the title on the page, and not in <title> element, beacause the <title> in your template (outerLayoutBase.html) it's out of the extraHead block.
I solve it in this way:

{% block title %}
             {% if data.piece %}
                {% if data.piece.seoTitle %}
                                {% set seoTitle = data.piece.seoTitle %}
                {% else %}
                                {% set seoTitle = data.piece.title %}
                {% endif %}
             {% else %}
                {% if data.page.seoTitle %}
                                {% set seoTitle = data.page.seoTitle %}
                {% else %}
                                {% set seoTitle = data.page.title %}
                {% endif %}
           {% endif %}
                {{seoTitle}}
{% endblock %}
{% block extraHead %}
                {% include "apostrophe-seo:view.html" %}
{% endblock %}

In apostrophe-seo:view.html the title is not used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.