drupal - Drupal 8 Google Analytics 模块,以编程方式获取 ID
问题描述
我正在尝试获取在 /admin/config/system/google-analytics 中设置的 Google Analytics ID (UA-xxxxxxx-yy)。是否可以将它作为控制器或表单中的变量,也许使用服务?
解决方案
从定义的模式中google_analytics.schema.yml
我们可以读到:
google_analytics.settings:
type: config_object
label: 'Google Analytics settings'
mapping:
account:
type: string
label: 'Web Property ID'
...
因此 Google Analytics ID 存储在 config 中,可以像这样检索:
$config = \Drupal::config('google_analytics.settings');
$id = $config->get('account');
推荐阅读
- python - Flask SQLAlchemy Marshmallow 一对多关系
- atlassian-sourcetree - SourceTree 在 Windows 上每隔几秒就会冻结一次
- android - 当子视图有点击监听器时,父视图上的 OnTouchListener 不会被调用
- java - Spring Data JPA 无法找到具有 id 的对象
- c# - 创建轮询系统以更新我的数据库用户订阅
- javascript - Angular Material如何在JS中选择组件
- python - OpenGL 将对象导出为 .png
- firebase - firebase 规则,创建用户 PERMISSION_DENIED: Permission denied
- java - 一天未使用后,MySQL Hibernate“已关闭”错误
- javascript - 如何在 VUE js 中动态暗示网格系统?