Skip to content

Getting Started

Introduction

In this documentation you'll find instructions for embedding Altmetric badges into your website. The badges are free to use for academic repositories and individual researchers.

If you want to use the badges on a site that isn't your lab or personal homepage, blog or an institutional repository then you should first contact us at [email protected] so that we can review your use case.

Warning

Do not use the badges commercially - on a journal, search engine, in an app etc. - without first talking to us! We're required by some of our data sources to keep track of who is using the badges and what for, and so need to issue you a license.

If you're an organization or publisher and would like to use these badges, please get in touch to discuss implementation.

Quick start

For researchers and academic repositories, the badges are simple to set up with a two step process:

  1. Add the following line of code anywhere on an HTML page:

    <script src='https://embed.altmetric.com/assets/embed.js'></script>
    

    Always load it from this address, and your badges stay up to date: you get new versions, features and fixes as and when they become available. Don't copy it to your own server or build it into your site's code (see Load the embed script from Altmetric).

  2. Add a div element specifying a DOI (digital object identifier), arXiv ID, Handle, PubMed ID, ISBN, URI or Altmetric ID wherever you want a badge to appear:

    <div class='altmetric-embed' data-badge-type='donut' data-doi="10.1038/nature.2012.9872"></div>
    

Replace the contents of data-doi with the DOI of the article you want the badge to represent: alternatively you can use a data-arxiv-id attribute containing an arXiv ID, data-handle attribute containing a Handle, data-isbn attribute containing an ISBN, data-uri attribute containing a URI or data-pmid attribute containing a PubMed ID.

If it isn't possible for you to set the data identifier attribute you can leave it empty and the embed script will look for a DOI in the dc:identifier or citation_doi <meta> tags of the current page. Contact us if you need any help with this.

That's it! You'll end up with a badge that looks like this:


You can customize how the badge looks, add popovers or display a breakdown of where an article has been mentioned by customizing the embed. See Customizations for more information.

Please see our full terms and conditions for more information.

Badge versions

There are two versions of the badges. We recommend version 2.

Feature Version 1 Version 2
Sources shown Up to 8 Up to 12, with new shading
Bar order Reverse colour order, news on the right The details page's "Mentioned by" order, news first
Image addresses /v1/donut/ /v2/donut/
Image sizes The size you ask for Never smaller than a minimum size

The embed code above gives you version 2 with no change on your side. The version only matters if you link to badge images directly.

Version 1 is still there so that existing /v1/donut/ links keep working, and for images smaller than version 2's minimum sizes. Version 1 will be retired, so move your links to /v2/donut/ when you can.

Accessibility

Altmetric badges, the popover and the details are designed to meet WCAG 2.2 level AA. Four parts of that depend on how you embed them: showing the source breakdown, the space around a small badge, making a text badge in a sentence stand out, and room for the focus outline.

Which setups meet WCAG 2.2 AA, and what your page must also do. The playground checks the badge you configure against the same rules.

Badge Meets WCAG 2.2 AA when
donut, medium-donut, large-donut It has a popover (data-badge-popover) or details (data-badge-details).
large-bar It has a popover or details.
bar, medium-bar It has a popover or details, and at least 10 pixels of space around it.
Small badges (the default, 1, 4 and the older 3) It has a popover or details, and at least 10 pixels of space around it.
text Inside a sentence: it's underlined. On its own: its link has a target of at least 24 by 24 pixels. A popover or details is optional, as it has no colours.
Every badge It has at least 4 pixels of room inside any element of yours with overflow: hidden, so the focus outline isn't cut off.

A donut, bar or small badge without a popover or details doesn't meet WCAG 2.2 AA on its own: its colours are the only way it shows where the attention came from. Every option still works, and the choice is yours; the notes below explain each requirement.

Show the source breakdown with the badge

Every badge except the text badge shows the sources of attention as colours, and each colour stands for a source (red for news, for example). To meet WCAG 2.2 AA for 1.4.1 Use of Color, the same information has to be available as text where the badge is. The source breakdown does this: each source by name, with its count.

Show it with the badge, using either:

  1. data-badge-popover: the breakdown opens when a reader hovers over or tabs to the badge; or
  2. data-badge-details: the breakdown is shown next to the badge all the time.

Without either, the colours are the only way your page shows where the attention came from, and the breakdown is a click away on the details page. With it, the colours are no longer the only way, which also covers the contrast between the segments (1.4.11 Non-text Contrast).

Badges smaller than 24 by 24 pixels

To meet WCAG 2.2 AA for 2.5.8 Target Size, you must either:

  1. use a badge that is at least 24 by 24 pixels: any donut (donut, medium-donut, large-donut) or the large-bar; or
  2. leave space around a smaller badge: keep at least 10 pixels between it and any other link, button or badge, above, below and beside it.

The badges smaller than 24 by 24 pixels are the small badges (the default, 1, 4 and the older 3, 15 to 20 pixels tall), the bar and medium-bar (15 and 18 pixels tall), and the text badge. A text badge inside a sentence or paragraph is exempt: 2.5.8 makes an exception for links in text. On its own, it needs a bigger target instead of space (below), as its link can be one digit wide.

The space doesn't need to be clickable: it just mustn't contain anything else that is, such as another link, button or badge. Text, images and empty space are fine. Put it outside the badge, for example as a margin:

.altmetric-embed { margin: 10px; }

A text badge on its own needs a target of at least 24 by 24 pixels:

.altmetric-embed[data-badge-type='text'] a { display: inline-block; min-width: 24px; min-height: 24px; line-height: 24px; text-align: center; }

Don't apply this to a text badge inside a sentence: it's exempt there, and the taller box would push the lines apart.

Ten pixels is enough beside other badges and anything at least 24 by 24 pixels. Beside a smaller link or button, or with less space, for example in a tightly packed list of publications, a badge meets 2.5.8 only if a circle 24 pixels across, centred on it, overlaps no other link, button or badge, and no other small target's circle.

A text badge inside a sentence

A text badge is a link showing the score, and it takes your page's own link style. Inside a sentence it must stand out from the words around it by more than colour alone (1.4.1 Use of Color). The simplest way is to underline it:

.altmetric-embed[data-badge-type='text'] a { text-decoration: underline; }

If your page's links are told apart from text by colour only, without an underline, the link colour needs a contrast of at least 3:1 with the text around it, plus another cue, such as an underline, when it's hovered over or focused.

Leave room for the focus outline

This applies to every badge type. When a keyboard user tabs to a badge, or to a link in its breakdown, a blue outline is drawn 4 pixels outside it (2.4.7 Focus Visible). If the badge sits right at the edge of an element of yours with overflow: hidden, that element cuts the outline off. Leave at least 4 pixels between the badge and every edge of that element, for example:

.altmetric-embed { margin: 4px; }

A small badge with the 10-pixel margin from the warning above already has the room it needs.

Technical information

Altmetric badges are delivered by Cloudfront where possible so latency should be very low.

Load the embed script from Altmetric

Always load the embed script with the tag from the Quick start:

<script src='https://embed.altmetric.com/assets/embed.js'></script>

embed.js always loads the latest badge code, so your badges get new versions, features and fixes as and when they become available, with nothing to change on your side. A copy is frozen at the version you copied and gets none of them. So:

  • Don't copy embed.js to your own server, or paste or build its code into your site's own scripts.
  • Don't link to the files it loads, such as altmetric_badges-….js or embed-….css. Their names change with every release.
  • Exclude it from caching and minifying plugins. Plugins that combine or minify scripts, such as many WordPress caching plugins, can save a copy of embed.js, and that copy stops getting updates. It's already minified and compressed, so excluding embed.altmetric.com costs nothing.
  • Allow whole hosts or folders in a Content Security Policy, not single files. If your site has a Content Security Policy, in a header or a <meta> tag, add these sources to the directives that restrict each resource type, keeping the sources they already allow:

    Directive Add
    script-src https://embed.altmetric.com/assets/ and https://api.altmetric.com/
    style-src https://embed.altmetric.com/assets/
    style-src-attr 'unsafe-inline'
    img-src https://badges.altmetric.com and https://cdn.altmetric.com

    Add a row's sources only if your policy already restricts that type, through the directive itself or one it falls back to (style-src, then default-src, for style-src-attr; default-src for the others). If you add a directive your policy didn't have, copy the sources of the one it falls back to into it first, or it will block your own resources.

    The badges set their size and spacing in style attributes; style-src-attr 'unsafe-inline' allows those without allowing inline <style> blocks.

    If your policy uses nonces, hashes, 'strict-dynamic', or script-src-elem or style-src-elem, contact us and we'll help you set it up.

    A policy that names a single file, such as https://embed.altmetric.com/assets/altmetric_badges-….js, blocks the badges as soon as we release a new version.

How the embed script finds badges

The embed script becomes active after the page DOM has loaded and looks for elements with the altmetric-embed class and a related data-{{identifier_type}} identifier attribute. You can see a full list of supported identifier types here.

If you're adding Altmetric badges to the DOM after the page has loaded (via AJAX, for example) then you can ask the Altmetric embed script to search the page again for new matches by calling the _altmetric_embed_init function in Javascript:

<script>
    _altmetric_embed_init();
</script>

If you only want to load Altmetric badges from a specific container (e.g. a new div containing several elements with the altmetric-embed class loaded via AJAX) rather than searching the whole page, you can pass an element or a string selector as a "context" argument to _altmetric_embed_init:

<script>
    _altmetric_embed_init(document.getElementById('new-container'));
    _altmetric_embed_init('#new-container');
</script>