|
| 1 | +<!-- Global site tag (gtag.js) - Google Analytics --> |
| 2 | +<script async="async" src="https://www.googletagmanager.com/gtag/js?id=YOUR ACCOUNT CODE"></script> |
| 3 | +<script> |
| 4 | + window.dataLayer = window.dataLayer || []; |
| 5 | + function gtag(){dataLayer.push(arguments);} |
| 6 | + gtag('js', new Date()); gtag('config', 'YOUR ACCOUNT CODE'); |
| 7 | +</script> |
| 8 | +<script> |
| 9 | + window.addEventListener("load", enableAnalyticsEventCapture, false); |
| 10 | + |
| 11 | + function enableAnalyticsEventCapture() { |
| 12 | + // Download button |
| 13 | + $(document).on("click", ".btn-download", function() { |
| 14 | + var category = $(this).text(); |
| 15 | + var label = getFileId($(this)); |
| 16 | + gtag('event', 'Download',{'event_category' : category, |
| 17 | + 'event_label' : label}); |
| 18 | + }); |
| 19 | + |
| 20 | + // Request Access button |
| 21 | + $(document).on("click", ".btn-request", function() { |
| 22 | + var category = $(this).text(); |
| 23 | + var label = getFileId($(this)); |
| 24 | + gtag('event', 'Request Access', {'event_category' : category, |
| 25 | + 'event_label' : label}); |
| 26 | + }); |
| 27 | + |
| 28 | + // Explore button |
| 29 | + $(document).on("click", ".btn-explore + ul.dropdown-menu li a", function() { |
| 30 | + var category = $(this).text(); |
| 31 | + var label = getFileId($(this)); |
| 32 | + gtag('event', 'Explore', {'event_category' : category, |
| 33 | + 'event_label' : label}); |
| 34 | + }); |
| 35 | + |
| 36 | + // Compute button |
| 37 | + $(document).on("click", ".btn-compute", function() { |
| 38 | + var category = $(this).text(); |
| 39 | + var label = getFileId($(this)); |
| 40 | + gtag('event', 'Compute', {'event_category' : category, |
| 41 | + 'event_label' : label}); |
| 42 | + }); |
| 43 | + |
| 44 | + // Preview button |
| 45 | + $(document).on("click", ".btn-preview", function() { |
| 46 | + var category = $(this).text(); |
| 47 | + var label = getFileId($(this)); |
| 48 | + gtag('event', 'Preview', {'event_category' : category, |
| 49 | + 'event_label' : label}); |
| 50 | + }); |
| 51 | + |
| 52 | + // Cite button |
| 53 | + $(document).on("click", ".downloadCitation + ul.dropdown-menu li a", function() { |
| 54 | + var category = $(this).text(); |
| 55 | + var label = 'Unknown'; |
| 56 | + if($('#fileForm').length > 0) { |
| 57 | + label = stripId($('#fileForm').attr('action')); |
| 58 | + } else if($('#datasetForm').length > 0) { |
| 59 | + label = stripId($('#datasetForm').attr('action')); |
| 60 | + } |
| 61 | + gtag('event', 'Download Citation', {'event_category' : category, |
| 62 | + 'event_label' : label}); |
| 63 | + }); |
| 64 | + |
| 65 | + // Export Metadata button |
| 66 | + $(document).on("click", ".btn-export + ul.dropdown-menu li a", function() { |
| 67 | + var category = $(this).text(); |
| 68 | + var label = 'Unknown'; |
| 69 | + if($('#fileForm').length > 0) { |
| 70 | + label = stripId($('#fileForm').attr('action')); |
| 71 | + } else if($('#datasetForm').length > 0) { |
| 72 | + label = stripId($('#datasetForm').attr('action')); |
| 73 | + } |
| 74 | + gtag('event', 'Export Metadata', {'event_category' : category, |
| 75 | + 'event_label' : label}); |
| 76 | + }); |
| 77 | + |
| 78 | + // Contact button |
| 79 | + $(document).on("click", ".btn-contact", function() { |
| 80 | + var category = $(this).text(); |
| 81 | + var label = 'Unknown'; |
| 82 | + if($('#fileForm').length > 0) { |
| 83 | + label = stripId($('#fileForm').attr('action')); |
| 84 | + } else if($('#datasetForm').length > 0) { |
| 85 | + label = stripId($('#datasetForm').attr('action')); |
| 86 | + } else if($('#dataverseForm').length > 0) { |
| 87 | + label = stripAlias($('#dataverseForm').attr('action')); |
| 88 | + } |
| 89 | + gtag('event', 'Contact', {'event_category' : category, |
| 90 | + 'event_label' : label}); |
| 91 | + }); |
| 92 | + |
| 93 | + // Share button |
| 94 | + $(document).on("click", 'div[id$="shareDialog"] a[class^="sharrre"]', function() { |
| 95 | + var sharrreVal = $(this).attr('class'); |
| 96 | + var category = sharrreVal.substring(sharrreVal.indexOf('-') + 1) ; |
| 97 | + var label = 'Unknown'; |
| 98 | + if($('#fileForm').length > 0) { |
| 99 | + label = stripId($('#fileForm').attr('action')); |
| 100 | + } else if($('#datasetForm').length > 0) { |
| 101 | + label = stripId($('#datasetForm').attr('action')); |
| 102 | + } else if($('#dataverseForm').length > 0) { |
| 103 | + label = stripAlias($('#dataverseForm').attr('action')); |
| 104 | + } |
| 105 | + gtag('event', 'Share', {'event_category' : category, |
| 106 | + 'event_label' : label}); |
| 107 | + }); |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | + function getFileId(target) { |
| 112 | + var label = 'Unknown'; |
| 113 | + if(target.parents('th').length>0) { |
| 114 | + //Special case - the Download button that downloads all selected files in the dataset |
| 115 | + label = 'file(s) from ' + stripId($('#datasetForm').attr('action')); |
| 116 | + } else { |
| 117 | + var row = target.parents('tr')[0]; |
| 118 | + if(row != null) { |
| 119 | + //finds the file id/DOI in the Dataset page |
| 120 | + label = $(row).find('td.col-file-metadata > a').attr('href'); |
| 121 | + } else { |
| 122 | + //finds the file id/DOI in the file page |
| 123 | + label = $('#fileForm').attr('action'); |
| 124 | + } |
| 125 | + label = stripId(label); |
| 126 | + } |
| 127 | + return label; |
| 128 | + } |
| 129 | + |
| 130 | + |
| 131 | + function stripId(label) { |
| 132 | + var index = label.indexOf('&'); |
| 133 | + if(index == -1) index = label.length; |
| 134 | + if(label.indexOf('persistentId=') >= 0) { |
| 135 | + label = label.substring(label.indexOf('persistentId=') + 13, index); |
| 136 | + } |
| 137 | + if(label.indexOf('fileId=') >= 0) { |
| 138 | + label = label.substring(label.indexOf('fileId=') + 7, index); |
| 139 | + } |
| 140 | + return(label); |
| 141 | + } |
| 142 | + |
| 143 | + function stripAlias(label) { |
| 144 | + var index = label.length; |
| 145 | + label = label.substring(label.indexOf('/dataverse/') + 11, index).split(/[?#]/)[0]; |
| 146 | + return(label); |
| 147 | + } |
| 148 | +</script> |
0 commit comments