TYPO3 使用打字稿根据域设置 Google Analytics 标记

问题描述 投票:0回答:1

我有一个多域,我想在其中使用打字稿设置 (TYPO3 V11) 设置单独的 Google Analytics 标记。

我从

constants.typoscript
开始:

myExt {
  googleAnalytics {
    default = G-SITE1
    site2 = G-SITE2
  }
}

随后是

setup.typoscript
,效果很好:

# google analytics
page.headerData.3 = TEXT
page.headerData.3.value(
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={$myExt.googleAnalytics.default}"></script>
    ...
)

我认为以下应该可行,但我尝试的所有变体都失败了:

# Multidomain
config.googleAnalytics = {$myExt.googleAnalytics.default}

[request.getNormalizedParams().getHttpHost() == "site2.com"]
    config.googleAnalytics = {$myExt.googleAnalytics.site2}
[END]

# google analytics
page.headerData.3 = TEXT
page.headerData.3.value(
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={$config.googleAnalytics}"></script>
    ...
)
typo3 typoscript typo3-11.x
1个回答
0
投票

您可以根据不同域的根页面 uid 设置常量值。

常量.typoscript

myExt.googleAnalytics = G-SITE1

[tree.rootLine[0]["uid"] == ROOT-PAGE-UID]
    myExt.googleAnalytics = G-SITE2
[END]

设置.打字稿

# google analytics
page.headerData.3 = TEXT
page.headerData.3.value(
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={$myExt.googleAnalytics}"></script>
    ...
)

有关条件的文档: https://docs.typo3.org/m/typo3/reference-typoscript/11.5/en-us/Conditions/Index.html#tree-rootline

© www.soinside.com 2019 - 2024. All rights reserved.