

If we want to set the profile after the code is built, we can use a Java VM argument at application launch. The key to this command is the -P flag, which is used to specify the profile to use for the build.
#SPRINGBOOT VERSION INSTALL#
Here is how this is done using Maven as the build tool: $ mvn -Pprod clean install

When building the application for production, we need to specify the PROD profile is to be used so that the real tracking ID values are used. This will prevent any page loads and triggered events from logging data to the Google platform.

That's it! Now whenever the application is built and run without specifying the profile – for example from within an IDE like Spring Tool Suite, Eclipse, or IntelliJ – the DEV profile will be chosen by default and dummy values will be substituted for the Google tracking IDs. Window.dataLayer = window.dataLayer || įunction gtag())( window, document, 'script', 'dataLayer', This tracking ID gets embedded into your site via an HTML code snippet provided by Google: If you've used these tools before, you'll know that in order to link your website to your Google Analytics account, Google provides a Tracking ID in the following format: UA-123456789-1 Google Search Console provides information about how Google crawls your site, how many sites link back to yours, and where your site ranks based on search keywords. When a site user executes the event, a call gets made to Google Analytics, which logs the event. This is done by defining Tag Manager listeners that link up to specific HTML elements on your website, which wait for the specified events (like a click or scroll) to occur. Google Tag Manager integrates with Google Analytics and allows developers to define the events that get tracked by Google Analytics. Google Analytics links up to your domain and tracks a wide breadth of statistics including page views, session information, audience location, and event triggers in historical and real-time contexts.
#SPRINGBOOT VERSION FREE#
The following free Google tools provide these services: If you are a web developer with an active site, it is a good bet that you use the Google platform for your analytics, event tracking, conversion tracking, and search engine ranking statistics. Overview of Google Analytics and Google Tag Manager In order to make this concept clearer, let's consider a real-world example involving Google Analytics and Google Tag Manager configuration on a Spring Boot site, which I'll go over in detail in the next few sections. Within each of these files, properties can be defined that will only be applied when the corresponding profile is active. These files need to be named the following: We can do this by adding the following to the application.properties file: we need to create the two new environment-specific property files (in the same path as the existing application.properties file), one to be used by the DEV profile and one to be used by the PROD profile. the profile that the app is currently being run with). Our first task will be to add a parameter in that file which will tell Spring to use a different environment-specific property file corresponding to the active profile (i.e. By default, Spring Boot parses a file called application.properties – located in the src/main/resources directory – to identify configuration information. Profiles work in conjunction with Spring Boot properties files. Note the true tag, which means that the development profile will be used by default assuming no profile is specified at build time. We can easily define the profiles by adding the following XML to the project's pom.xml file: In this article, we will create a DEV profile and PROD profile to enable environment-specific configuration properties. If no profile is specified, the default will be used. Each time the app is built, the developer can specify which profile to use. A profile in Spring Boot can be thought of as a context that defines a specific set of app settings, variables, and behaviors. However, usually some customization is necessary and oftentimes we need environment specific customization. This means that the vast majority of app configurations use sensible default values that can be overridden when necessary, but in general a Spring Boot app will work out of the box with no custom configuration required. One of the core design principles behind Spring Boot is that it encourages convention over configuration. I use this method for my website, Initial Commit, which is built using Spring Boot, the Thymeleaf template engine, and is hosted on AWS Elastic Beanstalk.

In order to demonstrate how profiles work, we'll visit an example using Google Analytics and Google Tag Manager for tracking site metrics. This article applies to sites created with the Spring Boot framework, using Apache Maven as the build tool.
