AMP 自定义 GA 维度在 GTM 中不起作用

AMP Custom GA Dimensions Not Working in GTM

我是 运行 一个同时拥有传统页面和 AMP 页面的 WordPress 网站。两个版本都使用 GTM,但 AMP 版本无法找到我的自定义变量。 AMP 页面正在验证,所以我认为我定义自定义变量的方式存在问题

我正在使用以下代码定义 AMP 页面上的变量。有什么我想念的地方不对劲吗?要查看 AMP 页面示例,请访问 https://cellculturedish.com/evolution-stem-cell-culture-cell-derived-extracellular-matrices/amp/.

<body>
<!-- Google Tag Manager -->
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=GTM-xxxxxxxxx.url=SOURCE_URL" data-credentials="include">
<?php if ( is_singular() ) { ?>

<?php global $post; ?>

<?php $categories = get_the_category( $post->ID ); ?>
<?php $primary_category = $categories[0]; ?>

<?php $post_sponsorship = get_field('post_sponsorship', $post->ID); ?>
<?php $is_sponsored = $post_sponsorship['is_sponsored']; ?>

<?php $author = 'Multiple Authors'; ?>
<?php $author_options = get_field('author_options', $post->ID); ?>

<?php if ( $author_options == 'ccd' && get_field('ccd_author') ) { ?>
    <?php $author_obj = get_field('ccd_author', $post->ID); ?>
    <?php $author = get_userdata( $author_obj ); ?>
    <?php $author = $author->data->display_name; ?>
<?php } elseif ( $author_options == 'guest_post' && count( get_field('contributing_experts', $post->ID) ) == 1 ) { ?>
    <?php $author_array = get_field('contributing_experts', $post->ID); ?>
    <?php $author = get_expert_title( $author_array[0] ); ?>
<?php } ?>

<script type="application/json">
    {
        "vars": {
            "publishDate": "<?php echo get_the_date('', $post->ID); ?>",
            "postCategory":"<?php echo $primary_category->name; ?>",
            "isSponsored": "<?php echo $sponsored = $post_sponsorship['is_sponsored'] == true ? 'true' : 'false'; ?>",
            <?php if ( $post_sponsorship['is_sponsored'] == true && $post_sponsorship['sponsor'] != null ) { ?>
            "postSponsor": "<?php echo get_the_title( $post_sponsorship['sponsor'] ); ?>",
            <?php } ?>
            "postAuthor": "<?php echo $author; ?>"
        }
    }
</script>
<?php } ?>

在 GTM 中为 "vars" 下的所有自定义维度创建 AMP 变量,如下所示:

接下来转到您的 GA 标签,在 "more settings" > "custom dimensions" 下为您的自定义维度添加正确的索引号和您刚刚为它们创建的 amp 变量名称: