javascript - Can't set different title on Google Analytics - Stack Overflow

I'm trying to set up a different page's title. I put that code on the head of the page:<sc

I'm trying to set up a different page's title. I put that code on the head of the page:

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics/analytics.js','ga');

    ga('create', 'UA-XXXXXXX-Y');
    ga('send', 'pageview');
    ga('set', 'title', 'Invitation');
</script>

I'd like to set up the 'title' as 'Invitation' but I have no feedback from Google Analytic's side. Obviously I changed UA-XXXXXXX-Y into my personal code. Right now I can only see that the page has been visited but it has the page's default title instead of the overridden one.

I'm trying to set up a different page's title. I put that code on the head of the page:

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics./analytics.js','ga');

    ga('create', 'UA-XXXXXXX-Y');
    ga('send', 'pageview');
    ga('set', 'title', 'Invitation');
</script>

I'd like to set up the 'title' as 'Invitation' but I have no feedback from Google Analytic's side. Obviously I changed UA-XXXXXXX-Y into my personal code. Right now I can only see that the page has been visited but it has the page's default title instead of the overridden one.

Share Improve this question asked Oct 16, 2013 at 19:35 GiulioGiulio 8038 silver badges22 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Pass the title as an additional and optional parameter when you send the pageview.

ga('send', 'pageview', {
    title: 'Invitation'
});

There is more info on page tracking on google developers.

You'd need to swap the send and set calls. Any set calls need to be before a send call.

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics./analytics.js','ga');

    ga('create', 'UA-XXXXXXX-Y');
    ga('set', 'title', 'Invitation');
    ga('send', 'pageview');
</script>

FYI - By utilizing the set mand you'll be changing the page title for all subsequent calls on that page. If you pass it as an optional parameter as in Blexy's example, it'll only change it for that single call. All subsequent calls will then use the default value.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742299883a4417837.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信