From b9aee93ae33b8cf25755abcc36fd610b9bd7f604 Mon Sep 17 00:00:00 2001 From: Andy Spaven <16537059+AndySpaven@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:58:13 +0000 Subject: [PATCH] APSR-1767 - Add GTM script to redoc view page (#486) --- .../apidocumentation/config/ApplicationConfig.scala | 8 ++++++++ .../controllers/OpenApiDocumentationController.scala | 3 ++- .../views/OpenApiViewRedoc.scala.html | 12 +++++++++++- conf/application.conf | 5 +++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/uk/gov/hmrc/apidocumentation/config/ApplicationConfig.scala b/app/uk/gov/hmrc/apidocumentation/config/ApplicationConfig.scala index 0972d0eb..be76102c 100644 --- a/app/uk/gov/hmrc/apidocumentation/config/ApplicationConfig.scala +++ b/app/uk/gov/hmrc/apidocumentation/config/ApplicationConfig.scala @@ -58,6 +58,9 @@ trait ApplicationConfig { def oasFetchResolvedMaxDuration: Long def oasFetchResolvedUsingHttps: Boolean + + def trackingConsentUrl: String + def gtmContainer: String } @Singleton @@ -117,4 +120,9 @@ class ApplicationConfigImpl @Inject() (config: Configuration) } } + // Needed for GTM on the redoc rendered page + val trackingConsentUrl: String = + config.get[String]("tracking-consent-frontend.url") + + val gtmContainer: String = config.get[String]("tracking-consent-frontend.gtm.container") } diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala index d40f822b..a588a0ca 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala @@ -45,6 +45,7 @@ import uk.gov.hmrc.apidocumentation.models._ import uk.gov.hmrc.apidocumentation.services.{ApiDefinitionService, LoggedInUserService, NavigationService} import uk.gov.hmrc.apidocumentation.util.ApplicationLogger import uk.gov.hmrc.apidocumentation.views.html._ +import play.api.i18n.MessagesProvider @Singleton class OpenApiDocumentationController @Inject() ( @@ -74,7 +75,7 @@ class OpenApiDocumentationController @Inject() ( sidebarLinks = navigationService.sidebarNavigation() ) - private def doRenderApiDocumentation(service: ServiceName, version: ApiVersionNbr, apiOption: Option[ExtendedApiDefinition])(implicit request: Request[AnyContent]): Future[Result] = { + private def doRenderApiDocumentation(service: ServiceName, version: ApiVersionNbr, apiOption: Option[ExtendedApiDefinition])(implicit request: Request[AnyContent], messagesProvider: MessagesProvider): Future[Result] = { def renderDocumentationPage(apiName: String): Future[Result] = { successful(Ok(openApiViewRedoc(service, version, apiName))) } diff --git a/app/uk/gov/hmrc/apidocumentation/views/OpenApiViewRedoc.scala.html b/app/uk/gov/hmrc/apidocumentation/views/OpenApiViewRedoc.scala.html index 029d692d..90c65134 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/OpenApiViewRedoc.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/OpenApiViewRedoc.scala.html @@ -17,10 +17,20 @@ @import views.html.helper.CSPNonce @import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ @import uk.gov.hmrc.apiplatform.modules.common.domain.models._ +@import uk.gov.hmrc.apidocumentation.config._ @this() -@(serviceName: ServiceName, version: ApiVersionNbr, apiName: String)(implicit requestHeader: RequestHeader) +@(serviceName: ServiceName, version: ApiVersionNbr, apiName: String)(implicit requestHeader: RequestHeader, appConfig: ApplicationConfig, messages: Messages) + + + +