Skip to content

Commit a24495e

Browse files
authored
Merge pull request #775 from AtlasOfLivingAustralia/feature/fathom
Adding fathom analytics
2 parents e9141ba + 85c2305 commit a24495e

File tree

24 files changed

+326
-586
lines changed

24 files changed

+326
-586
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
profileHubVersion=4.0-MANGROVE-SNAPSHOT
1+
profileHubVersion=4.1-SNAPSHOT
22
grailsVersion=5.2.4
33
grailsGradlePluginVersion=5.2.3
44
groovyVersion=3.0.11

grails-app/assets/javascripts/profileEditor/controllers/DoiController.js

+6
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ profileEditor.controller('DoiController', function (util, $filter, profileServic
3737
}
3838
});
3939
}
40+
41+
self.trackDownload = function (context, opusId, profileId, publicationId) {
42+
var url = context + '/opus/' + opusId + '/profile/' + profileId + '/publication/' + publicationId + '/file'
43+
profileService.trackPageview(url);
44+
}
45+
4046
});

grails-app/assets/javascripts/profileEditor/controllers/ExportController.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Export controller
33
*/
4-
profileEditor.controller('ExportController', function (util, $window, $modal, $http, config) {
4+
profileEditor.controller('ExportController', function (util, $window, $modal, $http, config, profileService) {
55
var self = this;
66

77
self.profileId = util.getEntityId("profile");
@@ -49,6 +49,8 @@ profileEditor.controller('ExportController', function (util, $window, $modal, $h
4949
} else {
5050
$http.get(url);
5151
}
52+
53+
profileService.trackPageview(url);
5254
});
5355
}
5456
});

grails-app/assets/javascripts/profileEditor/directives/publication.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ profileEditor.directive('publication', function ($browser) {
1212
prefix: '@'
1313
},
1414
templateUrl: '/profileEditor/publication.htm',
15-
controller: ['$scope', 'config', function ($scope, config) {
15+
controller: ['$scope', 'config', 'profileService', function ($scope, config, profileService) {
1616
$scope.context = config.contextPath;
17+
$scope.trackDownload = function (context, opusId, profileId, publicationId) {
18+
var url = context + '/opus/' + opusId + '/profile/' + profileId + '/publication/' + publicationId + '/file'
19+
profileService.trackPageview(url);
20+
}
1721
}],
1822
link: function (scope, element, attrs, ctrl) {
1923

grails-app/assets/javascripts/profileEditor/services/ProfileService.js

+16
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,22 @@ profileEditor.service('profileService', function ($http, util, $cacheFactory, co
12771277
loadMasterListItems: function(opus) {
12781278
var future = $http.get(util.contextRoot() + '/opus/' + opus.uuid + '/masterList/keybaseItems', {disableAlertOnFailure: true });
12791279
return util.toStandardPromise(future);
1280+
},
1281+
1282+
trackPageview: function (url, referrer) {
1283+
if ((typeof fathom !== 'undefined') && fathom.trackPageview) {
1284+
var payload = { };
1285+
if (url) {
1286+
payload.url = url;
1287+
}
1288+
1289+
if (referrer) {
1290+
payload.referrer = referrer;
1291+
}
1292+
1293+
console.debug("Tracking pageview with payload: " + JSON.stringify(payload));
1294+
fathom.trackPageview(payload);
1295+
}
12801296
}
12811297
}
12821298
});

grails-app/assets/javascripts/profileEditor/templates/publication.tpl.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
</div>
1919
<div class="col-md-2">
20-
<a ng-href="{{context}}/opus/{{opusId}}/profile/{{profileId}}/publication/{{publication.uuid}}/file"
20+
<a ng-href="{{context}}/opus/{{opusId}}/profile/{{profileId}}/publication/{{publication.uuid}}/file" ng-click="trackDownload(context, opusId, profileId, publication.uuid)"
2121
target="_blank"><span class="fa fa-download color--green">&nbsp;Download</span></a>
2222
</div>
2323
</div>
-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import au.org.ala.profile.analytics.GoogleAnalyticsClientFactory
2-
31
// Place your Spring DSL code here
42
beans = {
5-
6-
googleAnalyticsClientFactory(GoogleAnalyticsClientFactory) {
7-
// override with beans.googleAnalyticsClientFactory.baseUrl property
8-
baseUrl = 'https://ssl.google-analytics.com'
9-
}
10-
googleAnalyticsClient(googleAnalyticsClientFactory: 'getInstance') { }
113
}

grails-app/controllers/au/org/ala/profile/api/ApiController.groovy

+72-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package au.org.ala.profile.api
22

33
import au.ala.org.ws.security.RequireApiKey
4-
import au.org.ala.profile.analytics.Analytics
54
import au.org.ala.profile.hub.BaseController
65
import au.org.ala.profile.hub.MapService
76
import au.org.ala.profile.hub.ProfileService
@@ -21,7 +20,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement
2120
import io.swagger.v3.oas.annotations.security.SecurityScheme
2221
import au.org.ala.plugins.openapi.Path
2322

24-
@Analytics
2523
@SecurityScheme(name = "auth",
2624
type = SecuritySchemeType.HTTP,
2725
scheme = "bearer"
@@ -36,6 +34,78 @@ class ApiController extends BaseController {
3634
MapService mapService
3735
ApiService apiService
3836

37+
@Path("/api/opus/{opusId}")
38+
@Operation(
39+
summary = "Get collection (opus) details",
40+
operationId = "/api/opus/{opusId}",
41+
method = "GET",
42+
responses = [
43+
@ApiResponse(
44+
responseCode = "200",
45+
content = @Content(
46+
mediaType = "application/json",
47+
array = @ArraySchema(
48+
schema = @Schema(
49+
implementation = OpusResponse.class
50+
)
51+
)
52+
),
53+
headers = [
54+
@Header(name = 'Access-Control-Allow-Headers', description = "CORS header", schema = @Schema(type = "String")),
55+
@Header(name = 'Access-Control-Allow-Methods', description = "CORS header", schema = @Schema(type = "String")),
56+
@Header(name = 'Access-Control-Allow-Origin', description = "CORS header", schema = @Schema(type = "String"))
57+
]
58+
),
59+
@ApiResponse(responseCode = "400",
60+
description = "opusId is a required parameter"),
61+
@ApiResponse(responseCode = "403",
62+
description = "You do not have the necessary permissions to perform this action."),
63+
@ApiResponse(responseCode = "405",
64+
description = "An unexpected error has occurred while processing your request."),
65+
@ApiResponse(responseCode = "404",
66+
description = "Collection not found"),
67+
@ApiResponse(responseCode = "500",
68+
description = "An unexpected error has occurred while processing your request.")
69+
],
70+
parameters = [
71+
@Parameter(
72+
name = "opusId",
73+
in = ParameterIn.PATH,
74+
required = true,
75+
description = "Collection id"
76+
),
77+
@Parameter(name = "Access-Token",
78+
in = ParameterIn.HEADER,
79+
required = false,
80+
description = "Access token to read private collection"),
81+
@Parameter(name = "Accept-Version",
82+
in = ParameterIn.HEADER,
83+
required = true,
84+
description = "The API version",
85+
schema = @Schema(
86+
name = "Accept-Version",
87+
type = "string",
88+
defaultValue = '1.0',
89+
allowableValues = ["1.0"]
90+
)
91+
)
92+
],
93+
security = [@SecurityRequirement(name="auth"), @SecurityRequirement(name = "oauth")]
94+
)
95+
def getOpus () {
96+
if (!params.opusId) {
97+
badRequest "opusId is a required parameter"
98+
} else {
99+
Map opus = profileService.getOpus(params.opusId)
100+
if (!opus) {
101+
notFound()
102+
} else {
103+
opus.remove('accessToken')
104+
render opus as JSON
105+
}
106+
}
107+
}
108+
39109
@Path("/api/opus/{opusId}/profile")
40110
@Operation(
41111
summary = "List profiles in a collection",

grails-app/controllers/au/org/ala/profile/api/ApiInterceptor.groovy

+10-13
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ class ApiInterceptor {
2727
def method = controllerClass?.getMethod(actionName, [] as Class[])
2828

2929
if (authorization) {
30-
def user = authService.userDetails()
31-
if (user) {
32-
if (params.opusId && (opus = profileService.getOpus(params.opusId))) {
33-
params.isOpusPrivate = opus.privateCollection
34-
if ((params.isOpusPrivate
35-
|| controllerClass?.isAnnotationPresent(RequiresAccessToken)
36-
|| method?.isAnnotationPresent(RequiresAccessToken)
37-
) && (token != opus.accessToken)) {
38-
log.warn("No valid access token for opus ${opus.uuid} when calling ${controllerName}/${actionName}")
39-
authorised = false
40-
} else {
41-
authorised = true
42-
}
30+
if (params.opusId && (opus = profileService.getOpus(params.opusId))) {
31+
params.isOpusPrivate = opus.privateCollection
32+
if ((params.isOpusPrivate
33+
|| controllerClass?.isAnnotationPresent(RequiresAccessToken)
34+
|| method?.isAnnotationPresent(RequiresAccessToken)
35+
) && (token != opus.accessToken)) {
36+
log.warn("No valid access token for opus ${opus.uuid} when calling ${controllerName}/${actionName}")
37+
authorised = false
38+
} else {
39+
authorised = true
4340
}
4441
}
4542
}

grails-app/controllers/au/org/ala/profile/hub/AnalyticsInterceptor.groovy

-136
This file was deleted.

grails-app/controllers/au/org/ala/profile/hub/ExportController.groovy

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package au.org.ala.profile.hub
22

3-
import au.org.ala.profile.analytics.Analytics
43
import grails.converters.JSON
54
import org.springframework.web.context.request.RequestContextHolder
65

@@ -9,7 +8,6 @@ class ExportController extends BaseController {
98
ProfileService profileService
109
ExportService exportService
1110

12-
@Analytics
1311
def getPdf() {
1412
if (!params.profileId || !params.opusId) {
1513
badRequest "profileId and opusId are required parameters"

grails-app/controllers/au/org/ala/profile/hub/ProfileController.groovy

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package au.org.ala.profile.hub
22

3-
import au.org.ala.profile.analytics.Analytics
43
import au.org.ala.profile.security.PrivateCollectionSecurityExempt
54
import au.org.ala.profile.security.Secured
65
import au.org.ala.web.AuthService
@@ -532,7 +531,6 @@ class ProfileController extends BaseController {
532531
}
533532
}
534533

535-
@Analytics
536534
def proxyPublicationDownload() {
537535
final pubId = params.publicationId as String
538536
if (!pubId) {

grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class UrlMappings {
257257

258258
// The following are APIs.
259259
group("/api") {
260+
get "/opus/$opusId" (version: "1.0", controller: "api", action: "getOpus", namespace: "v1")
260261
get "/opus/$opusId/profile" (version: "1.0", controller: "api", action: "getProfiles", namespace: "v1")
261262
get "/opus/$opusId/profile/$profileId" (version: "1.0", controller: "api", action: "get", namespace: "v1")
262263
get "/opus/$opusId/profile/$profileId/image" (version: "1.0", controller: "api", action: "getImages", namespace: "v1")

0 commit comments

Comments
 (0)