Skip to content

Commit

Permalink
APPS-1213 (#1067)
Browse files Browse the repository at this point in the history
* Add dataLayer

* Add e2e test

* Add title to dataLayer

* Add type of resource

* Add datalayer to collection page and remove null values from object

* Fix linting issues

* Fix broken cypress data error

* Add page_type and human readable language field

* Fix photographer_tesim

* fix nested iframes dl viewer relates cypress test

* fix nested iframes issue
pghorpade authored Dec 18, 2021
1 parent 68456ab commit ec5864c
Showing 5 changed files with 117 additions and 36 deletions.
85 changes: 51 additions & 34 deletions app/views/catalog/_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
<% if Flipflop.sinai? %>
<%# --------- Back to Search Results ----- %>

<div class='item-page__metadata-wrapper-results--sinai'>
<%= link_back_to_catalog label: '← Back to Search Results', class: 'si-link si-link-search-results' %>
<%#= link_to image_tag('iiif-logo.png', alt: 'IIIF Manifest'), @document[:iiif_manifest_url_ssi], class: 'si-link-iiif' %>
<div class='item-page__metadata-wrapper'>
<%= render 'catalog/work_record--ursus/primary_metadata', document: document %>
<%= render 'catalog/work_record--ursus/secondary_metadata', document: document %>
</div>

<%# ---------- IIIF & Tooltip ------------ %>
<div class='si-link-iiif'>
<div class='iiif-tooltip--sinai' data-toggle="tooltip" data-placement="bottom" data-html="true" title="IIIF Manifest URL"><%= link_to image_tag('iiif-logo.png', alt: 'IIIF Manifest'), @document[:iiif_manifest_url_ssi], class: 'si-link-iiif' %></div>
</div>
</div>

<%# ----------- Shelfmark --------------- %>
<div class='title-row-show--siani'>
<%= @document[:shelfmark_ssi] %>
</div>

<div class='item-page__metadata-wrapper'>
<%= render 'catalog/work_record--sinai/primary_metadata', document: document %>
<%= render 'catalog/work_record--sinai/secondary_metadata', document: document %>
</div>

<%# ----------- Ursus --------------- %>
<% else %>
<div class='item-page__metadata-wrapper'>
<%= render 'catalog/work_record--ursus/primary_metadata', document: document %>
<%= render 'catalog/work_record--ursus/secondary_metadata', document: document %>
</div>
<% end %>

<!-- <script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script> -->
<script>
dataLayer.push({
'event':'pageLoad',
'page_type':'asset',
'AltTitle.other': <%= raw @document[:alternative_title_tesim].to_json %> === null ? undefined : <%= raw @document[:alternative_title_tesim].to_json.html_safe %>,
'Coverage.geographic': <%= raw @document[:location_tesim].to_json %> === null ? undefined : <%= raw @document[:location_tesim].to_json.html_safe %>,
'Date.normalized': <%= raw @document[:normalized_date_sim].to_json %> === null ? undefined : <%= raw @document[:normalized_date_sim].to_json.html_safe %>,
'Description.fundingNote': <%= raw @document[:funding_note_tesim].to_json %> === null ? undefined : <%= raw @document[:funding_note_tesim].to_json.html_safe %>,
'Finding Aid URL': <%= raw @document[:finding_aid_url_ssm].to_json %> === null ? undefined : <%= raw @document[:finding_aid_url_ssm].to_json.html_safe %>,
'Item ARK': <%= raw @document[:ark_ssi].to_json %> === null ? undefined : <%= raw @document[:ark_ssi].to_json.html_safe %>,
'Language': <%= raw @document[:human_readable_language_tesim].to_json %> === null ? undefined : <%= raw @document[:human_readable_language_tesim].to_json.html_safe %>,
'Name.architect': <%= raw @document[:architect_tesim].to_json %> === null ? undefined : <%= raw @document[:architect_tesim].to_json.html_safe %>,
'Name.artist': <%= raw @document[:artist_tesim].to_json %> === null ? undefined : <%= raw @document[:artist_tesim].to_json.html_safe %>,
'Name.caligrapher': <%= raw @document[:calligrapher_tesim].to_json %> === null ? undefined : <%= raw @document[:calligrapher_tesim].to_json.html_safe %>,
'Name.cartographer': <%= raw @document[:cartographer_tesim].to_json %> === null ? undefined : <%= raw @document[:cartographer_tesim].to_json.html_safe %>,
'Name.commentator': <%= raw @document[:commentator_tesim].to_json %> === null ? undefined : <%= raw @document[:commentator_tesim].to_json.html_safe %>,
'Name.composer': <%= raw @document[:composer_tesim].to_json %> === null ? undefined : <%= raw @document[:composer_tesim].to_json.html_safe %>,
'Name.creator': <%= raw @document[:creator_tesim].to_json %> === null ? undefined : <%= raw @document[:creator_tesim].to_json.html_safe %>,
'Name.director': <%= raw @document[:director_tesim].to_json %> === null ? undefined : <%= raw @document[:director_tesim].to_json.html_safe %>,
'Name.editor': <%= raw @document[:editor_tesim].to_json %> === null ? undefined : <%= raw @document[:editor_tesim].to_json.html_safe %>,
'Name.engraver': <%= raw @document[:engraver_tesim].to_json %> === null ? undefined : <%= raw @document[:engraver_tesim].to_json.html_safe %>,
'Name.illuminator': <%= raw @document[:illuminator_tesim].to_json %> === null ? undefined : <%= raw @document[:illuminator_tesim].to_json.html_safe %>,
'Name.illustrator': <%= raw @document[:illustrator_tesim].to_json %> === null ? undefined : <%= raw @document[:illustrator_tesim].to_json.html_safe %>,
'Name.interviewee': <%= raw @document[:interviewee_tesim].to_json %> === null ? undefined : <%= raw @document[:interviewee_tesim].to_json.html_safe %>,
'Name.interviewer': <%= raw @document[:interviewer_tesim].to_json %> === null ? undefined : <%= raw @document[:interviewer_tesim].to_json.html_safe %>,
'Name.lyricist': <%= raw @document[:lyricist_tesim].to_json %> === null ? undefined : <%= raw @document[:lyricist_tesim].to_json.html_safe %>,
'Name.photographer': <%= raw @document[:photographer_tesim].to_json %> === null ? undefined : <%= raw @document[:photographer_tesim].to_json.html_safe %>,
'Name.printmaker': <%= raw @document[:printmaker_tesim].to_json %> === null ? undefined : <%= raw @document[:printmaker_tesim].to_json.html_safe %>,
'Name.producer': <%= raw @document[:producer_tesim].to_json %> === null ? undefined : <%= raw @document[:producer_tesim].to_json.html_safe %>,
'Name.recipient': <%= raw @document[:recipient_tesim].to_json %> === null ? undefined : <%= raw @document[:recipient_tesim].to_json.html_safe %>,
'Name.rubricator': <%= raw @document[:rubricator_tesim].to_json %> === null ? undefined : <%= raw @document[:rubricator_tesim].to_json.html_safe %>,
'Name.subject': <%= raw @document[:named_subject_tesim].to_json %> === null ? undefined : <%= raw @document[:named_subject_tesim].to_json.html_safe %>,
'Name.scribe': <%= raw @document[:scribe_tesim].to_json %> === null ? undefined : <%= raw @document[:scribe_tesim].to_json.html_safe %>,
'Name.translator': <%= raw @document[:translator_tesim].to_json %> === null ? undefined : <%= raw @document[:translator_tesim].to_json.html_safe %>,
'Opac url': <%= raw @document[:opac_url_ssi].to_json %> === null ? undefined : <%= raw @document[:opac_url_ssi].to_json.html_safe %>,
'Project Name': <%= raw @document[:member_of_collections_ssim].to_json %> === null ? undefined : <%= raw @document[:member_of_collections_ssim].to_json.html_safe %>, // Not sure if pulling from the right field there is no project_tesin field in solr
'Publisher.publisherName': <%= raw @document[:publisher_tesim].to_json %> === null ? undefined : <%= raw @document[:publisher_tesim].to_json.html_safe %>,
'Repository': <%= raw @document[:repository_tesim].to_json %> === null ? undefined : <%= raw @document[:repository_tesim].to_json.html_safe %>,
'Subject geographic': <%= raw @document[:subject_geographic_tesim].to_json %> === null ? undefined : <%= raw @document[:subject_geographic_tesim].to_json.html_safe %>,
'Subject name': <%= raw @document[:named_subject_tesim].to_json %> === null ? undefined : <%= raw @document[:named_subject_tesim].to_json.html_safe %>,
'Subject temporal': <%= raw @document[:subject_temporal_tesim].to_json %> === null ? undefined : <%= raw @document[:subject_topic_tesim].to_json.html_safe %>,
'Subject topic': <%= raw @document[:subject_topic_tesim].to_json.html_safe %> === null ? undefined : <%= raw @document[:subject_temporal_tesim].to_json.html_safe %>,
'Title': <%= raw @document[:title_tesim].to_json %> === null ? undefined : <%= raw @document[:title_tesim].to_json.html_safe %>,
'Type.genre': <%= raw @document[:genre_tesim].to_json %> === null ? undefined : <%= raw @document[:genre_tesim].to_json.html_safe %>,
'Type.typeOfResource':<%= raw @document[:human_readable_resource_type_tesim].to_json %> === null ? undefined : <%= raw @document[:human_readable_resource_type_tesim].to_json.html_safe %>
})
</script>
47 changes: 47 additions & 0 deletions app/views/catalog/collection_record/_collection_record.html.erb
Original file line number Diff line number Diff line change
@@ -15,3 +15,50 @@
</div>

</div>
<script>
dataLayer.push({
'event':'pageLoad',
'page_type':'collection',
'AltTitle.other': <%= raw @document[:alternative_title_tesim].to_json %> === null ? undefined : <%= raw @document[:alternative_title_tesim].to_json.html_safe %>,
'Coverage.geographic': <%= raw @document[:location_tesim].to_json %> === null ? undefined : <%= raw @document[:location_tesim].to_json.html_safe %>,
'Date.normalized': <%= raw @document[:normalized_date_sim].to_json %> === null ? undefined : <%= raw @document[:normalized_date_sim].to_json.html_safe %>,
'Description.fundingNote': <%= raw @document[:funding_note_tesim].to_json %> === null ? undefined : <%= raw @document[:funding_note_tesim].to_json.html_safe %>,
'Finding Aid URL': <%= raw @document[:finding_aid_url_ssm].to_json %> === null ? undefined : <%= raw @document[:finding_aid_url_ssm].to_json.html_safe %>,
'Item ARK': <%= raw @document[:ark_ssi].to_json %> === null ? undefined : <%= raw @document[:ark_ssi].to_json.html_safe %>,
'Language': <%= raw @document[:human_readable_language_tesim].to_json %> === null ? undefined : <%= raw @document[:human_readable_language_tesim].to_json.html_safe %>,
'Name.architect': <%= raw @document[:architect_tesim].to_json %> === null ? undefined : <%= raw @document[:architect_tesim].to_json.html_safe %>,
'Name.artist': <%= raw @document[:artist_tesim].to_json %> === null ? undefined : <%= raw @document[:artist_tesim].to_json.html_safe %>,
'Name.caligrapher': <%= raw @document[:calligrapher_tesim].to_json %> === null ? undefined : <%= raw @document[:calligrapher_tesim].to_json.html_safe %>,
'Name.cartographer': <%= raw @document[:cartographer_tesim].to_json %> === null ? undefined : <%= raw @document[:cartographer_tesim].to_json.html_safe %>,
'Name.commentator': <%= raw @document[:commentator_tesim].to_json %> === null ? undefined : <%= raw @document[:commentator_tesim].to_json.html_safe %>,
'Name.composer': <%= raw @document[:composer_tesim].to_json %> === null ? undefined : <%= raw @document[:composer_tesim].to_json.html_safe %>,
'Name.creator': <%= raw @document[:creator_tesim].to_json %> === null ? undefined : <%= raw @document[:creator_tesim].to_json.html_safe %>,
'Name.director': <%= raw @document[:director_tesim].to_json %> === null ? undefined : <%= raw @document[:director_tesim].to_json.html_safe %>,
'Name.editor': <%= raw @document[:editor_tesim].to_json %> === null ? undefined : <%= raw @document[:editor_tesim].to_json.html_safe %>,
'Name.engraver': <%= raw @document[:engraver_tesim].to_json %> === null ? undefined : <%= raw @document[:engraver_tesim].to_json.html_safe %>,
'Name.illuminator': <%= raw @document[:illuminator_tesim].to_json %> === null ? undefined : <%= raw @document[:illuminator_tesim].to_json.html_safe %>,
'Name.illustrator': <%= raw @document[:illustrator_tesim].to_json %> === null ? undefined : <%= raw @document[:illustrator_tesim].to_json.html_safe %>,
'Name.interviewee': <%= raw @document[:interviewee_tesim].to_json %> === null ? undefined : <%= raw @document[:interviewee_tesim].to_json.html_safe %>,
'Name.interviewer': <%= raw @document[:interviewer_tesim].to_json %> === null ? undefined : <%= raw @document[:interviewer_tesim].to_json.html_safe %>,
'Name.lyricist': <%= raw @document[:lyricist_tesim].to_json %> === null ? undefined : <%= raw @document[:lyricist_tesim].to_json.html_safe %>,
'Name.photographer': <%= raw @document[:photographer_tesim].to_json %> === null ? undefined : <%= raw @document[:photographer_tesim].to_json.html_safe %>,
'Name.printmaker': <%= raw @document[:printmaker_tesim].to_json %> === null ? undefined : <%= raw @document[:printmaker_tesim].to_json.html_safe %>,
'Name.producer': <%= raw @document[:producer_tesim].to_json %> === null ? undefined : <%= raw @document[:producer_tesim].to_json.html_safe %>,
'Name.recipient': <%= raw @document[:recipient_tesim].to_json %> === null ? undefined : <%= raw @document[:recipient_tesim].to_json.html_safe %>,
'Name.rubricator': <%= raw @document[:rubricator_tesim].to_json %> === null ? undefined : <%= raw @document[:rubricator_tesim].to_json.html_safe %>,
'Name.subject': <%= raw @document[:named_subject_tesim].to_json %> === null ? undefined : <%= raw @document[:named_subject_tesim].to_json.html_safe %>,
'Name.scribe': <%= raw @document[:scribe_tesim].to_json %> === null ? undefined : <%= raw @document[:scribe_tesim].to_json.html_safe %>,
'Name.translator': <%= raw @document[:translator_tesim].to_json %> === null ? undefined : <%= raw @document[:translator_tesim].to_json.html_safe %>,
'Opac url': <%= raw @document[:opac_url_ssi].to_json %> === null ? undefined : <%= raw @document[:opac_url_ssi].to_json.html_safe %>,
'Project Name': <%= raw @document[:member_of_collections_ssim].to_json %> === null ? undefined : <%= raw @document[:member_of_collections_ssim].to_json.html_safe %>, // Not sure if pulling from the right field there is no project_tesin field in solr
'Publisher.publisherName': <%= raw @document[:publisher_tesim].to_json %> === null ? undefined : <%= raw @document[:publisher_tesim].to_json.html_safe %>,
'Repository': <%= raw @document[:repository_tesim].to_json %> === null ? undefined : <%= raw @document[:repository_tesim].to_json.html_safe %>,
'Subject geographic': <%= raw @document[:subject_geographic_tesim].to_json %> === null ? undefined : <%= raw @document[:subject_geographic_tesim].to_json.html_safe %>,
'Subject name': <%= raw @document[:named_subject_tesim].to_json %> === null ? undefined : <%= raw @document[:named_subject_tesim].to_json.html_safe %>,
'Subject temporal': <%= raw @document[:subject_temporal_tesim].to_json %> === null ? undefined : <%= raw @document[:subject_topic_tesim].to_json.html_safe %>,
'Subject topic': <%= raw @document[:subject_topic_tesim].to_json.html_safe %> === null ? undefined : <%= raw @document[:subject_temporal_tesim].to_json.html_safe %>,
'Title': <%= raw @document[:title_tesim].to_json %> === null ? undefined : <%= raw @document[:title_tesim].to_json.html_safe %>,
'Type.genre': <%= raw @document[:genre_tesim].to_json %> === null ? undefined : <%= raw @document[:genre_tesim].to_json.html_safe %>,
'Type.typeOfResource':<%= raw @document[:human_readable_resource_type_tesim].to_json %> === null ? undefined : <%= raw @document[:human_readable_resource_type_tesim].to_json.html_safe %>
})
</script>
4 changes: 3 additions & 1 deletion app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@
<% end %>
<% end %>
<meta name="theme-color" content="#2774ae">

<script>
window.dataLayer = window.dataLayer || [];
</script>
<% if ENV["GOOGLE_TAG_MGR_ID"] %>
<script type="text/javascript" id='analytics-script'>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
12 changes: 12 additions & 0 deletions e2e/cypress/integration/data_layer_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('Data Layer tests', () => {
it('Data Layer Loaded', () => {
cy.visit('/catalog/ark:/21198/zz0027xkn4');
cy.window().then((win)=>{
assert.isDefined(win.dataLayer, 'window.dataLayer is defined');
assert.equal(win.dataLayer[0].Title[0], 'Russian aviators meet the press after breaking the non-stop flight record, flying from Moscow to San Jacinto, 1937');
assert.equal(win.dataLayer[0]['Item ARK'], 'ark:/21198/zz0027xkn4');
assert.equal(win.dataLayer[0]['Type.genre'][0],'news photographs');
assert.equal(win.dataLayer[0]['Type.genre'][1],'cellulose nitrate film');
});
});
});
5 changes: 4 additions & 1 deletion e2e/cypress/integration/ursus_work_show_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

describe('Work show pages', () => {
it('Arganon (Praise) of Mary', () => {
cy.visit('/catalog/ark:/21198/zz0009q5nq');
@@ -9,7 +10,9 @@ describe('Work show pages', () => {
url:
'https://p-w-dl-viewer01.library.ucla.edu/#?manifest=https%3A%2F%2Fiiif.library.ucla.edu%2Fark%253A%252F21198%252Fzz0009q5nq%2Fmanifest',
});
cy.iframe().contains('div', 'Ms. 35 Arganon');
cy.iframe().within(() => {
cy.iframe().contains('div', 'Ms. 35 Arganon')
});
cy.percySnapshot();
});
});

0 comments on commit ec5864c

Please sign in to comment.