diff --git a/backend/explorer-core/autoconfigure/pom.xml b/backend/explorer-core/autoconfigure/pom.xml index 4f0f7f267..b498146f1 100644 --- a/backend/explorer-core/autoconfigure/pom.xml +++ b/backend/explorer-core/autoconfigure/pom.xml @@ -308,7 +308,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 ../../../pom.xml diff --git a/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/configuration/ParametersConfiguration.java b/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/configuration/ParametersConfiguration.java index b413d5283..84c1ff7d1 100644 --- a/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/configuration/ParametersConfiguration.java +++ b/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/configuration/ParametersConfiguration.java @@ -3,6 +3,7 @@ import org.royllo.explorer.core.util.parameters.IncomingRateLimitsParameters; import org.royllo.explorer.core.util.parameters.MempoolParameters; import org.royllo.explorer.core.util.parameters.OutgoingRateLimitsParameters; +import org.royllo.explorer.core.util.parameters.RoylloExplorerAnalyticsParameters; import org.royllo.explorer.core.util.parameters.RoylloExplorerParameters; import org.royllo.explorer.core.util.parameters.S3Parameters; import org.royllo.explorer.core.util.parameters.TAPDParameters; @@ -19,6 +20,9 @@ RoylloExplorerParameters.Api.class, RoylloExplorerParameters.Web.class, RoylloExplorerParameters.Content.class, + // Royllo explorer analytics configuration. + RoylloExplorerAnalyticsParameters.class, + RoylloExplorerAnalyticsParameters.Piwik.class, // S3 configuration. S3Parameters.class, // Mempool configuration. diff --git a/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/util/parameters/RoylloExplorerAnalyticsParameters.java b/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/util/parameters/RoylloExplorerAnalyticsParameters.java new file mode 100644 index 000000000..83bcf89c5 --- /dev/null +++ b/backend/explorer-core/autoconfigure/src/main/java/org/royllo/explorer/core/util/parameters/RoylloExplorerAnalyticsParameters.java @@ -0,0 +1,35 @@ +package org.royllo.explorer.core.util.parameters; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +/** + * Royllo explorer analytics parameters. + */ +@Validated +@Getter +@Setter +@ToString +@ConfigurationProperties(prefix = "royllo.explorer.analytics") +public class RoylloExplorerAnalyticsParameters { + + /** Piwik analytics. */ + private Piwik piwik = new Piwik(); + + /** Piwik parameters. */ + @Validated + @Getter + @Setter + @ToString + @ConfigurationProperties(prefix = "piwik") + public static class Piwik { + + /** Piwik tracking id. */ + private String trackingId; + + } + +} diff --git a/backend/explorer-core/starter/pom.xml b/backend/explorer-core/starter/pom.xml index 7191258a7..980e73722 100644 --- a/backend/explorer-core/starter/pom.xml +++ b/backend/explorer-core/starter/pom.xml @@ -114,7 +114,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 ../../../pom.xml diff --git a/backend/servers/explorer-api/pom.xml b/backend/servers/explorer-api/pom.xml index 00921e3f5..6fa73e901 100644 --- a/backend/servers/explorer-api/pom.xml +++ b/backend/servers/explorer-api/pom.xml @@ -310,7 +310,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 ../../../pom.xml diff --git a/backend/servers/explorer-batch/pom.xml b/backend/servers/explorer-batch/pom.xml index 426d4867e..1ac6a07a9 100644 --- a/backend/servers/explorer-batch/pom.xml +++ b/backend/servers/explorer-batch/pom.xml @@ -237,7 +237,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 ../../../pom.xml diff --git a/backend/servers/explorer-web/pom.xml b/backend/servers/explorer-web/pom.xml index 2785d2617..7474f8e92 100644 --- a/backend/servers/explorer-web/pom.xml +++ b/backend/servers/explorer-web/pom.xml @@ -291,7 +291,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 ../../../pom.xml diff --git a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/advice/ConfigurationControllerAdvice.java b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/advice/ConfigurationControllerAdvice.java index 6e1829832..f6de4f850 100644 --- a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/advice/ConfigurationControllerAdvice.java +++ b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/advice/ConfigurationControllerAdvice.java @@ -1,6 +1,7 @@ package org.royllo.explorer.web.util.advice; import lombok.RequiredArgsConstructor; +import org.royllo.explorer.core.util.parameters.RoylloExplorerAnalyticsParameters; import org.royllo.explorer.core.util.parameters.RoylloExplorerParameters; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -8,6 +9,7 @@ import static org.royllo.explorer.web.util.constants.ModelAttributeConstants.API_BASE_URL_ATTRIBUTE; import static org.royllo.explorer.web.util.constants.ModelAttributeConstants.CONTENT_BASE_URL_ATTRIBUTE; +import static org.royllo.explorer.web.util.constants.ModelAttributeConstants.PIWIK_ANALYTICS_TRACKING_ID_ATTRIBUTE; import static org.royllo.explorer.web.util.constants.ModelAttributeConstants.WEB_BASE_URL_ATTRIBUTE; /** @@ -20,6 +22,9 @@ public class ConfigurationControllerAdvice { /** Royllo explorer parameters. */ private final RoylloExplorerParameters roylloExplorerParameters; + /** Royllo explorer analytics parameters. */ + private final RoylloExplorerAnalyticsParameters roylloExplorerAnalyticsParameters; + @ModelAttribute public final void handleRequest(final Model model) { @@ -28,6 +33,8 @@ public final void handleRequest(final Model model) { model.addAttribute(WEB_BASE_URL_ATTRIBUTE, roylloExplorerParameters.getWeb().getBaseUrl()); model.addAttribute(CONTENT_BASE_URL_ATTRIBUTE, roylloExplorerParameters.getContent().getBaseUrl()); + // Set the analytics parameters. + model.addAttribute(PIWIK_ANALYTICS_TRACKING_ID_ATTRIBUTE, roylloExplorerAnalyticsParameters.getPiwik().getTrackingId()); } } diff --git a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/constants/ModelAttributeConstants.java b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/constants/ModelAttributeConstants.java index 1c632030a..f7aad14f4 100644 --- a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/constants/ModelAttributeConstants.java +++ b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/util/constants/ModelAttributeConstants.java @@ -18,6 +18,9 @@ public class ModelAttributeConstants { /** Content base url. */ public static final String CONTENT_BASE_URL_ATTRIBUTE = "contentBaseUrl"; + /** Piwik analytics tracking id. */ + public static final String PIWIK_ANALYTICS_TRACKING_ID_ATTRIBUTE = "piwikAnalyticsTrackingId"; + /** Query attribute. */ public static final String QUERY_ATTRIBUTE = "query"; diff --git a/backend/servers/explorer-web/src/main/resources/application-dev.properties b/backend/servers/explorer-web/src/main/resources/application-dev.properties index f525824c9..aeda682e9 100644 --- a/backend/servers/explorer-web/src/main/resources/application-dev.properties +++ b/backend/servers/explorer-web/src/main/resources/application-dev.properties @@ -3,6 +3,11 @@ royllo.explorer.api.base-url=http://localhost:9090/api royllo.explorer.web.base-url=http://localhost:3000 royllo.explorer.content.base-url=http://localhost:9093 +# +# ====================================================================================================================== +# Royllo explorer analytics configuration. +royllo.explorer.analytics.piwik.trackingId=00000000-0000-0000-0000-000000000000 +# # ====================================================================================================================== # Using Liquibase to import test data spring.liquibase.enabled=true diff --git a/backend/servers/explorer-web/src/main/resources/application.properties b/backend/servers/explorer-web/src/main/resources/application.properties index 4be47743c..2fc4b846e 100644 --- a/backend/servers/explorer-web/src/main/resources/application.properties +++ b/backend/servers/explorer-web/src/main/resources/application.properties @@ -6,7 +6,11 @@ # Royllo explorer configuration. royllo.explorer.api.base-url=https://api.explorer.royllo.org royllo.explorer.web.base-url=https://explorer.royllo.org -royllo.explorer.content.base-url=https://assets.royllo.org +royllo.explorer.content.base-url=http://localhost:9093 +# +# ====================================================================================================================== +# Royllo explorer analytics configuration. +royllo.explorer.analytics.piwik.trackingId=00000000-0000-0000-0000-000000000000 # # ====================================================================================================================== # Database access configuration. diff --git a/backend/servers/explorer-web/src/main/resources/templates/util/fragments/components/analytics_piwik.html b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/components/analytics_piwik.html new file mode 100644 index 000000000..9c93af915 --- /dev/null +++ b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/components/analytics_piwik.html @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/asset/layout.html b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/asset/layout.html index a120dadff..1259cad15 100644 --- a/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/asset/layout.html +++ b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/asset/layout.html @@ -14,6 +14,11 @@ + + + + +
diff --git a/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/default/layout.html b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/default/layout.html index 2935272bc..4522621a0 100644 --- a/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/default/layout.html +++ b/backend/servers/explorer-web/src/main/resources/templates/util/fragments/layouts/default/layout.html @@ -14,6 +14,11 @@ + + + + +
diff --git a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloCoinTest.java b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloCoinTest.java index aeea5f276..0f9a80e22 100644 --- a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloCoinTest.java +++ b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloCoinTest.java @@ -85,8 +85,8 @@ void assetPageGenesis(final HttpHeaders headers) throws Exception { .andExpect(content().string(containsString(">" + assetIdAlias + "<"))) .andExpect(content().string(containsString(">" + getMessage(messages, "asset.data.assetType.normal") + "<"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAmount() + "<"))) - .andExpect(content().string(not(containsString("src=" + "\"" + "null/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".txt")))) - .andExpect(content().string(containsString("href=" + "\"" + "null/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".txt"))) + .andExpect(content().string(not(containsString("src=" + "\"" + "https://assets.royllo.org/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".txt")))) + .andExpect(content().string(containsString("href=" + "\"" + "https://assets.royllo.org/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".txt"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getMetaDataHash() + "<"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getVersion() + "<"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getGenesisPoint() + "<"))) diff --git a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloNFTTest.java b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloNFTTest.java index 0e1ce9e7a..d8c5cb8c8 100644 --- a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloNFTTest.java +++ b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/asset/DisplayRoylloNFTTest.java @@ -85,8 +85,8 @@ void assetPageGenesis(final HttpHeaders headers) throws Exception { .andExpect(content().string(containsString(">" + assetIdAlias + "<"))) .andExpect(content().string(containsString(">" + getMessage(messages, "asset.data.assetType.collectible") + "<"))) .andExpect(content().string(not(containsString(">" + assetFromTest.getAsset().getAmount() + "<")))) - .andExpect(content().string(containsString("src=" + "\"" + "null/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".png"))) - .andExpect(content().string(containsString("href=" + "\"" + "null/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".png"))) + .andExpect(content().string(containsString("src=" + "\"" + "https://assets.royllo.org/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".png"))) + .andExpect(content().string(containsString("href=" + "\"" + "https://assets.royllo.org/" + assetFromTest.getAsset().getAssetGenesis().getAssetId() + ".png"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getMetaDataHash() + "<"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getVersion() + "<"))) .andExpect(content().string(containsString(">" + assetFromTest.getAsset().getAssetGenesis().getGenesisPoint() + "<"))) diff --git a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/AnalyticsPiwikTest.java b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/AnalyticsPiwikTest.java new file mode 100644 index 000000000..c95208f31 --- /dev/null +++ b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/AnalyticsPiwikTest.java @@ -0,0 +1,43 @@ +package org.royllo.explorer.web.test.controllers.util; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; + +import static org.hamcrest.Matchers.containsString; +import static org.royllo.test.TapdData.ROYLLO_COIN_ASSET_ID; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@DirtiesContext +@DisplayName("Analytics - Piwik tests") +@AutoConfigureMockMvc +@TestPropertySource(properties = {"royllo.explorer.analytics.piwik.trackingId=00000000-0000-0000-0000-000000000001"}) +public class AnalyticsPiwikTest { + + @Autowired + MockMvc mockMvc; + + @Test + @DisplayName("Piwik configured") + void piwikConfigured() throws Exception { + + // We test on each layout (home, asset). + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("(window, document, 'dataLayer', '00000000-0000-0000-0000-000000000001');"))); + + mockMvc.perform(get("/asset/" + ROYLLO_COIN_ASSET_ID)) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("(window, document, 'dataLayer', '00000000-0000-0000-0000-000000000001');"))); + + } + +} diff --git a/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/NoAnalyticsTest.java b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/NoAnalyticsTest.java new file mode 100644 index 000000000..3e234b3e1 --- /dev/null +++ b/backend/servers/explorer-web/src/test/java/org/royllo/explorer/web/test/controllers/util/NoAnalyticsTest.java @@ -0,0 +1,44 @@ +package org.royllo.explorer.web.test.controllers.util; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.royllo.test.TapdData.ROYLLO_COIN_ASSET_ID; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@DirtiesContext +@DisplayName("Analytics - no analytics tests") +@AutoConfigureMockMvc +@TestPropertySource(properties = {"royllo.explorer.analytics.piwik.trackingId="}) +public class NoAnalyticsTest { + + @Autowired + MockMvc mockMvc; + + @Test + @DisplayName("No analytics configured") + void noAnalyticsConfigured() throws Exception { + + // We test on each layout (home, asset). + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(content().string(not(containsString("(window, document, 'dataLayer'")))); + + mockMvc.perform(get("/asset/" + ROYLLO_COIN_ASSET_ID)) + .andExpect(status().isOk()) + .andExpect(content().string(not(containsString("(window, document, 'dataLayer'")))); + + } + +} diff --git a/backend/servers/explorer-web/src/test/resources/application.properties b/backend/servers/explorer-web/src/test/resources/application.properties index 7f8681ac3..69abd4f62 100644 --- a/backend/servers/explorer-web/src/test/resources/application.properties +++ b/backend/servers/explorer-web/src/test/resources/application.properties @@ -6,6 +6,12 @@ # Royllo explorer configuration. royllo.explorer.api.base-url=http://localhost:9090/api royllo.explorer.web.base-url=http://localhost:8080 +royllo.explorer.content.base-url=https://assets.royllo.org +# +# ====================================================================================================================== +# Royllo explorer analytics configuration. +royllo.explorer.analytics.piwik.trackingId= +# # # ====================================================================================================================== # Database access configuration. diff --git a/pom.xml b/pom.xml index e57abf4b8..80d0c0c62 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.royllo.explorer explorer - 0.1.1 + 0.1.2 Royllo - A Taproot asset explorer Royllo explorer allows you to search for Taproot assets created on the Bitcoin blockchain pom @@ -64,7 +64,7 @@ - 3.1.5 + 3.1.7 3.6.1 1.1.14 @@ -179,7 +179,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.5 + 3.1.7