Skip to content

Commit

Permalink
Merge pull request #775 from AtlasOfLivingAustralia/feature/fathom
Browse files Browse the repository at this point in the history
Adding fathom analytics
  • Loading branch information
schoicsiro committed Aug 21, 2023
2 parents e9141ba + 85c2305 commit 69b4660
Show file tree
Hide file tree
Showing 24 changed files with 326 additions and 586 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
profileHubVersion=4.0-MANGROVE-SNAPSHOT
profileHubVersion=4.1-SNAPSHOT
grailsVersion=5.2.4
grailsGradlePluginVersion=5.2.3
groovyVersion=3.0.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ profileEditor.controller('DoiController', function (util, $filter, profileServic
}
});
}

self.trackDownload = function (context, opusId, profileId, publicationId) {
var url = context + '/opus/' + opusId + '/profile/' + profileId + '/publication/' + publicationId + '/file'
profileService.trackPageview(url);
}

});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Export controller
*/
profileEditor.controller('ExportController', function (util, $window, $modal, $http, config) {
profileEditor.controller('ExportController', function (util, $window, $modal, $http, config, profileService) {
var self = this;

self.profileId = util.getEntityId("profile");
Expand Down Expand Up @@ -49,6 +49,8 @@ profileEditor.controller('ExportController', function (util, $window, $modal, $h
} else {
$http.get(url);
}

profileService.trackPageview(url);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ profileEditor.directive('publication', function ($browser) {
prefix: '@'
},
templateUrl: '/profileEditor/publication.htm',
controller: ['$scope', 'config', function ($scope, config) {
controller: ['$scope', 'config', 'profileService', function ($scope, config, profileService) {
$scope.context = config.contextPath;
$scope.trackDownload = function (context, opusId, profileId, publicationId) {
var url = context + '/opus/' + opusId + '/profile/' + profileId + '/publication/' + publicationId + '/file'
profileService.trackPageview(url);
}
}],
link: function (scope, element, attrs, ctrl) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,22 @@ profileEditor.service('profileService', function ($http, util, $cacheFactory, co
loadMasterListItems: function(opus) {
var future = $http.get(util.contextRoot() + '/opus/' + opus.uuid + '/masterList/keybaseItems', {disableAlertOnFailure: true });
return util.toStandardPromise(future);
},

trackPageview: function (url, referrer) {
if ((typeof fathom !== 'undefined') && fathom.trackPageview) {
var payload = { };
if (url) {
payload.url = url;
}

if (referrer) {
payload.referrer = referrer;
}

console.debug("Tracking pageview with payload: " + JSON.stringify(payload));
fathom.trackPageview(payload);
}
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
</div>
<div class="col-md-2">
<a ng-href="{{context}}/opus/{{opusId}}/profile/{{profileId}}/publication/{{publication.uuid}}/file"
<a ng-href="{{context}}/opus/{{opusId}}/profile/{{profileId}}/publication/{{publication.uuid}}/file" ng-click="trackDownload(context, opusId, profileId, publication.uuid)"
target="_blank"><span class="fa fa-download color--green">&nbsp;Download</span></a>
</div>
</div>
8 changes: 0 additions & 8 deletions grails-app/conf/spring/resources.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import au.org.ala.profile.analytics.GoogleAnalyticsClientFactory

// Place your Spring DSL code here
beans = {

googleAnalyticsClientFactory(GoogleAnalyticsClientFactory) {
// override with beans.googleAnalyticsClientFactory.baseUrl property
baseUrl = 'https://ssl.google-analytics.com'
}
googleAnalyticsClient(googleAnalyticsClientFactory: 'getInstance') { }
}
74 changes: 72 additions & 2 deletions grails-app/controllers/au/org/ala/profile/api/ApiController.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package au.org.ala.profile.api

import au.ala.org.ws.security.RequireApiKey
import au.org.ala.profile.analytics.Analytics
import au.org.ala.profile.hub.BaseController
import au.org.ala.profile.hub.MapService
import au.org.ala.profile.hub.ProfileService
Expand All @@ -21,7 +20,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.security.SecurityScheme
import au.org.ala.plugins.openapi.Path

@Analytics
@SecurityScheme(name = "auth",
type = SecuritySchemeType.HTTP,
scheme = "bearer"
Expand All @@ -36,6 +34,78 @@ class ApiController extends BaseController {
MapService mapService
ApiService apiService

@Path("/api/opus/{opusId}")
@Operation(
summary = "Get collection (opus) details",
operationId = "/api/opus/{opusId}",
method = "GET",
responses = [
@ApiResponse(
responseCode = "200",
content = @Content(
mediaType = "application/json",
array = @ArraySchema(
schema = @Schema(
implementation = OpusResponse.class
)
)
),
headers = [
@Header(name = 'Access-Control-Allow-Headers', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Methods', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Origin', description = "CORS header", schema = @Schema(type = "String"))
]
),
@ApiResponse(responseCode = "400",
description = "opusId is a required parameter"),
@ApiResponse(responseCode = "403",
description = "You do not have the necessary permissions to perform this action."),
@ApiResponse(responseCode = "405",
description = "An unexpected error has occurred while processing your request."),
@ApiResponse(responseCode = "404",
description = "Collection not found"),
@ApiResponse(responseCode = "500",
description = "An unexpected error has occurred while processing your request.")
],
parameters = [
@Parameter(
name = "opusId",
in = ParameterIn.PATH,
required = true,
description = "Collection id"
),
@Parameter(name = "Access-Token",
in = ParameterIn.HEADER,
required = false,
description = "Access token to read private collection"),
@Parameter(name = "Accept-Version",
in = ParameterIn.HEADER,
required = true,
description = "The API version",
schema = @Schema(
name = "Accept-Version",
type = "string",
defaultValue = '1.0',
allowableValues = ["1.0"]
)
)
],
security = [@SecurityRequirement(name="auth"), @SecurityRequirement(name = "oauth")]
)
def getOpus () {
if (!params.opusId) {
badRequest "opusId is a required parameter"
} else {
Map opus = profileService.getOpus(params.opusId)
if (!opus) {
notFound()
} else {
opus.remove('accessToken')
render opus as JSON
}
}
}

@Path("/api/opus/{opusId}/profile")
@Operation(
summary = "List profiles in a collection",
Expand Down
23 changes: 10 additions & 13 deletions grails-app/controllers/au/org/ala/profile/api/ApiInterceptor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ class ApiInterceptor {
def method = controllerClass?.getMethod(actionName, [] as Class[])

if (authorization) {
def user = authService.userDetails()
if (user) {
if (params.opusId && (opus = profileService.getOpus(params.opusId))) {
params.isOpusPrivate = opus.privateCollection
if ((params.isOpusPrivate
|| controllerClass?.isAnnotationPresent(RequiresAccessToken)
|| method?.isAnnotationPresent(RequiresAccessToken)
) && (token != opus.accessToken)) {
log.warn("No valid access token for opus ${opus.uuid} when calling ${controllerName}/${actionName}")
authorised = false
} else {
authorised = true
}
if (params.opusId && (opus = profileService.getOpus(params.opusId))) {
params.isOpusPrivate = opus.privateCollection
if ((params.isOpusPrivate
|| controllerClass?.isAnnotationPresent(RequiresAccessToken)
|| method?.isAnnotationPresent(RequiresAccessToken)
) && (token != opus.accessToken)) {
log.warn("No valid access token for opus ${opus.uuid} when calling ${controllerName}/${actionName}")
authorised = false
} else {
authorised = true
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package au.org.ala.profile.hub

import au.org.ala.profile.analytics.Analytics
import grails.converters.JSON
import org.springframework.web.context.request.RequestContextHolder

Expand All @@ -9,7 +8,6 @@ class ExportController extends BaseController {
ProfileService profileService
ExportService exportService

@Analytics
def getPdf() {
if (!params.profileId || !params.opusId) {
badRequest "profileId and opusId are required parameters"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package au.org.ala.profile.hub

import au.org.ala.profile.analytics.Analytics
import au.org.ala.profile.security.PrivateCollectionSecurityExempt
import au.org.ala.profile.security.Secured
import au.org.ala.web.AuthService
Expand Down Expand Up @@ -532,7 +531,6 @@ class ProfileController extends BaseController {
}
}

@Analytics
def proxyPublicationDownload() {
final pubId = params.publicationId as String
if (!pubId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class UrlMappings {

// The following are APIs.
group("/api") {
get "/opus/$opusId" (version: "1.0", controller: "api", action: "getOpus", namespace: "v1")
get "/opus/$opusId/profile" (version: "1.0", controller: "api", action: "getProfiles", namespace: "v1")
get "/opus/$opusId/profile/$profileId" (version: "1.0", controller: "api", action: "get", namespace: "v1")
get "/opus/$opusId/profile/$profileId/image" (version: "1.0", controller: "api", action: "getImages", namespace: "v1")
Expand Down
Loading

0 comments on commit 69b4660

Please sign in to comment.