Ready to Learn?Ex Libris products all provide open APIs

Tech Blog

 

Altmetric.com Tab

Ido Peled on December 11th, 2012

Description

The following code and steps can be used to incorporate the Altmetric.com (http://altmetric.com/) widget in Primo.

*An additional script is now available that allows to integrate Altmetric in the brief result list (via DOI or PMID)
 

Note from the Altmetric website: “Right now the API limits by IP on an hourly and daily basis. Check the X-HourlyRateLimit-Limit and X-DailyRateLimit-Limitheaders for the current limits. X-HourlyRateLimit-Remaining and X-DailyRateLimit-Remaining tell you how many calls you can make from your current IP.”
“An API key raises the rate limits significantly.” 

Notes:

  • The tab will only be available in the Primo Full Details page
  • The tab will only be displayed for records with a DOI 

    More information about Altmetric.com can be found on the Ex Libris Initiatives blog
 

Author: Ido Peled

Additional author(s): Timm Siewert (script for brief result list )

Year: 2012

License: BSD style

Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.

Skill required for using this code: Intermediate

 

State

Stable

 

Programming language

Javascript (not needed)

 

Using the following Ex Libris open interfaces

EXL Tab API: http://www.exlibrisgroup.org/display/Primo/EXL+Tab+API

 

Installation instructions

1.     Download and follow the instructions on the EXL Tab API http://www.exlibrisgroup.org/display/Primo/EXL+Tab+API
2.     Download the attached HTML files and place them in a web-accessible folder (folder on the server, Dropbox, etc.)
3.     Open the "altmetric_footer.html" file and change the following code to the URL you use for the "altmetric.html" file:
 
EXLTA_addTab('Metrics','metricsTab','http://..../altmetric.html',EXLTA_iframeTabHandler,false,metricsEvaluator);

 

4.     Open Primo Backoffice user interface
5.     Navigate to “Primo Home > Ongoing Configuration Wizards > Views Wizard”
6.     Open the relevant view for editing
7.     Click on “Customize Layout” from the first screen
8.     Change the “Page” dropdown box to “Full Display”
9.     Click on the "content - Div"
10.   Add a new tile using the "Add Tile" button on the right side of the screen
11.   Click on the "new tile"
12.   Change the "content" dropdown box to "Custom Tile"
13.   Enter the URL of the "altmetric_footer.html" file
14.   Continue to deploy the changes

That it! the new tab should be available from the Full Details page of relevant articles.

 

Screenshots

Screenshot of the Primo back office layout set with the new Altmetric.com tile

Screenshot of the new tab in action

 

Integration in the result list

It is possible to parse the DOI (and other identifiers like ISSN, ISBN, PMID) and integrate the Altmetric.com widget also in the brief result list.

 

Installation instructions

  1. Include the following script in your header.html 

 

<script type='text/javascript' src='https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js'></script>

 

  1. Navigate to “Primo Home > Ongoing Configuration Wizards > Views Wizard”
  2. Open the relevant view for editing
  3. Navigate to "Edit Brief Results Attributes" (Tiles Configuration)
  4. Add the identifier field to be displayed in the "Field to display in 3rd line of the brief results

6.     Save and continue
7.     Deploy the changes
8.     Integrate the following script in your footer.html file (for DOI or PMID):
 
//Altmetric.com integration with DOI

<script type="text/javascript">

$("h3.EXLResultFourthLine").each(function(){

            if($(this).children("b").text().match(/DOI/g)){

                myDOI=$(this).html().replace(/(.|\s)*?DOI:(.|\s)*?<\/b \s*(\S*)(.|\s)*/,''+'$3'+'');

                $(this).html('<br><div class="altmetric-embed" data badge-type="donut" data-doi="'+myDOI+'" ></div><br><br>');

        };

});

</script>

 

 

//Altmetric.com integration with PMID

<script type="text/javascript">

$("h3.EXLResultFourthLine").each(function(){

            if($(this).children("b").text().match(/PMID/g)){

                myPMID=$(this).html().replace(/(.|\s)*?PMID:(.|\s)*?(\d{8})<\/b>\s*(\S*)(.|\s)*?/,''+'$3'+'');

$(this).html('<br><div class="altmetric-embed"  data-hide-no-mentions="true" data-badge-popover="right" data-doi="'+myPMID+'" ></div><br>');

        };

});

</script>

 

9.     That´s it!

 

State Screenshots (for result list)

 

Example: Simple badge

 

*Please check the Altmetric website for other badges http://api.altmetric.com/embeds.html

 

*You can hide Altmetric from the result list – and only display it in the full title view. For this you can check whether  facets are available – if yes – hide the field with the identifier
 
$(document).ready(function() {

        if($('div.EXLFacetList').length){

            $('h3.EXLResultFourthLine').hide();

            }

        });
 

View links here:

 

Comments

Dec 20, 2012

Karsten Kryger Hansen

This will only work on the first record, since this code has hardcoded the selector for the id of the first record.

var doi = $(element).find('#details_0').attr('value');

 

Dec 20, 2012

Ido Peled

 

Hi Karsten,

 

You are absolutely right. I developed this for the Full Display page and not he Brief Results so I only had one record on that page. You can change the altmetric.html to take the DOI for each of the records in the Brief Results page.

Ido

 

Dec 20, 2012

Karsten Kryger Hansen

Hi Ido

Thanks for the clarification. I did not see that when I read about this component. I will see if we can make one that works on the full results page.

BR,
Karsten

 

 

Jan 5, 2013

Jim Adamson

Hi Ido,

This looks very interesting & useful, thanks! I got it working, but only after removing a fix to some code in the EXL API tab that resolved a problem with something else.

Just a few comments regarding the implementation.

1. I had already been experimenting with EXL Tab API so have EXLTabAPI.03b.js included in our Primo web pages. The file altmetric_footer.html pulls down a modified version of EXLTabAPI.03b.js called EXLTabAPI.js. This file has had the EXLTA_iframeTabHandler removed and the function transferred to altmetric_footer.html in a modified form. Why not leave the original EXLTA_iframeTabHandler intact in EXLTabAPI.js and create a copy of the function with a new name to retrieve the DOI in your altmetric_footer.html? If the original EXLTA_iframeTabHandler is then required for other purposes it is still available.

2. The file altmetric_footer.html pulls down jquery-latest.js, but jquery - albeit an older version - is already included with Primo, so why is this included again? It adds to page weight so seems unnecessary.

Kind regards,

Jim

 

 

Jan 6, 2013

Ido Peled

Hi Jim,

I'm happy to see this being used and looking forward to see it in production, so keep me posted.

Regarding your questions:

1.     I used a modified version of the EXLTabAPI.js simply because that's what I've been using which seemed simple to use and it worked..
2.     You're .right, no specific reason to re-import the JQuery

Best regards,
Ido

BTW, i've added the EXLTabAPI.js as an attachment.

 

 

Jan 31, 2013

Stephanie Young

Hi,

We can only use IE8 at my library and I was unable to get Altmetrics to work. At first I thought it might be our strict IE global settings, but I tried it on a non-work laptop with IE8 using the visitor wifi and still no joy.  Has anyone been able to get Altmetrics API working in IE8?

Best,

Steph

 

Mar 5, 2013

Lukas Koster

Thanks Ido, we will have a lookourselves.

Another question: the Metrics "tab will only be displayed for records with a DOI". I have the impression that the tab is always displayed for records with a DOI, even if there is no information available. Is that correct? Is there no way of checking before displaying? I haven't looked at the plugin in detail myself. Maybe you have a simple answer http://www.exlibrisgroup.org/images/icons/emoticons/smile.gif

 

 

Mar 5, 2013

Ido Peled

 

Hi Lukas,

 

What you describe is correct, for every record with DOI the Metrics tab will be displayed. I guess there is a way to check with Altmetric whether the information does exist but I was afraid that would significantly increase their usage (double the calls) and I wasn't sure if their infrastructure could support it.

 

In the altmetric.html there is a function that allows filtering the display. The current filter only checks for a DOI, you can extend it to check against Altmetric.com as well.

 

 

 

Mar 5, 2013

Lukas Koster

 

Thanks again. Will have a look

 

 

Aug 19, 2013

Richard Cross

 

Hi - this was working fine in our Primo staging environment, but is not currently returning any responses (even though the Almetrics API is still returning calls). For all the examples I've tried, including the direct URL in Ido's example above, only the 'Almetrics.com' link loads; and no dynamic data. I tried tracking back through the various JS-calling-more-JS files but couldn't immediately see the point of fail. It's a shame, as we were about to drop this into Production Primo!

 

 

Sep 3, 2013

Lukas Koster

Interesting new addition, Timm. It is good to be able to show Altmetrics in the brief results list. Two questions however: 

- as Richard Cross noted, the original full record version does not work anymore. 

- if the brief results script works, why not use an extra Metrics Tab there as well?

Lukas Koster

 

 

Sep 4, 2013

Timm Siewert

Hi Lukas,

with the new script you get as well Altmetrics in the full record. You can hide the display of Altmetrics in the brief result with this jQuery script:

$(document).ready(function() {

        if($('div.EXLFacetList').length){

            $('h3.EXLResultFourthLine').hide();

            }

        });

 

It checks whether facets are available - if yes - identifier (DOI, PMID) you need for the display of Altmetric are hidden.

Personally - I ´m not a big fan of additional tabs. Thinking about usability - one might ignore this feature.

I would suggest that you check the Altmetric site for possible badges (http://api.altmetric.com/embeds.html). For example it is possible to hide an Altmetric badge if there are no metrics for a DOI:

 

data-hide-no-mentions='true'

 

This could avoid confusion for the end user. However - it is also possible to use a tab - but that is not covered in this script so far.

 

Best regards,

Timm

 

 

Sep 4, 2013

Lukas Koster

OK, I need to check the new script then ;-)

About tabs: I thought it's the official Primo policy. Actually we're hiding as many tabs as possible already. But you have to be consistent. If you have a Metrics tab in the full record, then also in the brief results.

Thanks for clarifying

Lukas

 

 

Sep 4, 2013

Lukas Koster

I added this new script to our staging/test environment, and it works very well. The only issue I can see now is that when using the "data-hide-no-mentions='true'" option, some extra white lines are inserted before the snippets and availability label, for records with DOIs and without Altmetrics.

 

 

Sep 4, 2013

Timm Siewert

Hi Lukas,

you may want to delete (some of) the <br> tags in the script - they create some space.

Best,
Timm

 

 

Sep 15, 2013

Lukas Koster

I had to disable the new add-on again, because the IE browser crashed, apparently when there are more than just a few DOIs in the presented result set.

What is this IE problem, any ideas?

 

 

Mar 3, 2014

Andy MacKinnon

really liking having the embeddable badges in the brief results list although the IE8 problem is likely to prevent us being able to put this into our production service - has anyone managed to work round this?

thanks to all involved for the work on this,

andy