Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Google Tag Manager Functionality #76

Open
wants to merge 3 commits into
base: improve-build
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PortalApp/app/controller/AdvancedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ Ext.define('SpWebPortal.controller.AdvancedSearch', {
solr: true
},

gtmContainerId: null,

init: function() {
//console.info("AdvancedSearch.init");
var settingsStore = Ext.getStore('SettingsStore');
var settings = settingsStore.getAt(0);
this.gtmContainerId = settings.get('gtmContainerId');

this.control({
'advSrch button[itemid="search-btn"]': {
Expand Down Expand Up @@ -153,6 +158,13 @@ Ext.define('SpWebPortal.controller.AdvancedSearch', {
if (filterStr.length == 0) {
filterStr = "*";
}

if (this.gtmContainerId) {
window.dataLayer.push({
'event': 'search_query',
'searchQuery': filterStr
});
Comment on lines +163 to +166

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

}
this.searchFor('(' + filterStr + ')', images, maps, filterToMap);
}
});
18 changes: 18 additions & 0 deletions PortalApp/app/controller/Detailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ Ext.define('SpWebPortal.controller.Detailer', {
ignoreDetailsPageChange: true,
stdImgSize: 500,
collectionName: '',
gtmContainerId: null,

init: function() {
//console.info("Detailer.init");
var settingsStore = Ext.getStore('SettingsStore');
var settings = settingsStore.getAt(0);
this.stdImgSize = settings.get('imageViewSize');
this.collectionName = settings.get('collectionName');
this.gtmContainerId = settings.get('gtmContainerId');

this.control({
'actioncolumn[itemid="detail-popup-ctl"]': {
Expand Down Expand Up @@ -375,6 +377,14 @@ Ext.define('SpWebPortal.controller.Detailer', {
} else {
this.popupImageSrcReady(imgRecord, [isActualSize, imgWinOwner]);
}

if (this.gtmContainerId) {
window.dataLayer.push({
'event': 'image_detail',
'attachmentId': imgRecord.data.AttachmentID,
'attachmentTitle': imgRecord.data.Title
});
Comment on lines +382 to +386

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

}
},

popupDetails: function(records, showMap) {
Expand Down Expand Up @@ -517,6 +527,14 @@ Ext.define('SpWebPortal.controller.Detailer', {
} else {
this.detailPopWinShown(record, showMap);
}

if (this.gtmContainerId) {
window.dataLayer.push({
'event': 'record_detail',
'catalogNumber': record.data.catalogNumber
});
Comment on lines +532 to +535

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

}

},

detailPopWinShown: function(record, showMap) {
Expand Down
3 changes: 2 additions & 1 deletion PortalApp/app/model/SettingsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Ext.define('SpWebPortal.model.SettingsModel', {
{name: 'clusterAverageCenter', type: 'boolean', defaultValue: true},
{name: 'clusterMinimumClusterSize', type: 'int'},
{name: 'clusterIgnoreHiddenMarkers', type: 'boolean', defaultValue: true},
{name: 'clusterStyles', type: 'json'}
{name: 'clusterStyles', type: 'json'},
{name: 'gtmContainerId', type: 'string', default: null}
],

validations: [
Expand Down
20 changes: 20 additions & 0 deletions PortalApp/app/view/gtm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Google Tag Manager
*
* Conditionally loads GTM script into page `<head>` if `gtmContainerId` has
* been set in `settings.json`.
*/
var settingsJson = await fetch('resources/config/settings.json')
var settings = await settingsJson.json()
var gtmContainerId = settings[0].gtmContainerId ?? null

window.dataLayer = window.dataLayer || [];
if (gtmContainerId && document.readyState !== 'loading') {
var script = document.createElement('script')
script.innerHTML = `(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],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${gtmContainerId}')`
document.head.appendChild(script)
}
1 change: 1 addition & 0 deletions PortalApp/doc/RoughGuideToWebPortalSetup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ bottomHeight: height in pixels of the bottomBranding area.
bottomMarginLeft: CSS setting for bottomBranding content.
bottomMarginRight: CSS setting for bottomBranding content.
bottomWidth: width in pixels of bottomBranding content.
gtmContainerId: Google Tag Manager container ID.


###################################################################
Expand Down
3 changes: 3 additions & 0 deletions PortalApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=AIzaSyDYHJjsVAniNFUxSZnIO6pyVBxBqRt9gmw&sensor=false"></script>
<!--script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=false"></script-->

<!-- Google Tag Manager -->
<script type="module" src="app/view/gtm.js"></script>

<!-- Include the extjs translations -->
<!--script type="text/javascript" src="//cdn.sencha.com/ext/gpl/4.1.1/locale/ext-lang-sv_SE.js"></script-->

Expand Down
3 changes: 2 additions & 1 deletion PortalApp/resources/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"bottomHeight": null,
"bottomMarginLeft": null,
"bottomMarginRight": null,
"bottomWidth": null
"bottomWidth": null,
"gtmContainerId": null
}]