AMP自定义GA尺寸在GTM中不起作用

时间:2018-10-02 16:30:47

标签: google-analytics google-tag-manager amp-html

我正在运行一个既有传统页面又有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 } ?>

1 个答案:

答案 0 :(得分:1)

在GTM中为“变量”下的所有自定义维度创建AMP变量,如下所示: enter image description here

接下来转到您的GA标签,在“更多设置”>“自定义尺寸”下,为您的自定义尺寸添加正确的索引号以及您刚刚为其创建的放大器变量名称: enter image description here