Add Google Analytics to registrar console

To support the open source community, which may want to use different analytics services, we implement a soy template for analytics services that:

1) Does not require users to implement Google Analytics
2) Allows users to add their own analytics code to `Analytics.soy`
3) Gives users the flexibility to pass as much or as little static configuration to their custom analytics code as needed.
4) Ensures that users can merge upstream Nomulus code in the future without having to delete their custom analytics implementations
5) Does not allow code to be injected from configuration, which Soy as a framework actively discourages.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=248340081
This commit is contained in:
jianglai 2019-05-15 08:44:56 -07:00
parent 7f69ebc5d9
commit b12a462f5e
15 changed files with 135 additions and 3 deletions

View file

@ -35,6 +35,9 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.net.URI;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
@ -198,6 +201,22 @@ public final class RegistryConfig {
return config.registrarConsole.technicalDocsUrl;
}
/**
* Configuration for analytics services installed in the web console.
*
* @see google.registry.ui.server.registrar.ConsoleUiAction
* @see google.registry.ui.soy.AnalyticsSoyInfo
*/
@Provides
@Config("analyticsConfig")
public static Map<String, Object> provideAnalyticsConfig(RegistryConfigSettings config) {
// Can't be an ImmutableMap because it may contain null values.
HashMap<String, Object> analyticsConfig = new HashMap<>();
analyticsConfig.put(
"googleAnalyticsId", config.registrarConsole.analyticsConfig.googleAnalyticsId);
return Collections.unmodifiableMap(analyticsConfig);
}
/**
* Returns the Google Cloud Storage bucket for storing zone files.
*

View file

@ -154,6 +154,12 @@ public class RegistryConfigSettings {
public String announcementsEmailAddress;
public String integrationEmailAddress;
public String technicalDocsUrl;
public AnalyticsConfig analyticsConfig;
}
/** Configuration for analytics services installed in the registrar console */
public static class AnalyticsConfig {
public String googleAnalyticsId;
}
/** Configuration for monitoring. */

View file

@ -332,6 +332,11 @@ registrarConsole:
# URL linking to directory of technical support docs on the registry.
technicalDocsUrl: http://example.com/your_support_docs/
# Configuration for all analytics services installed in the web console
analyticsConfig:
# Google Analytics account where data on console use is sent, optional
googleAnalyticsId: null
monitoring:
# Max queries per second for the Google Cloud Monitoring V3 (aka Stackdriver)
# API. The limit can be adjusted by contacting Cloud Support.