我正在尝试使用Google Analytics注册网站的所有流量,并根据Microsoft.AspNet.Identity角色拆分报告。
我没有找到任何允许这样做的东西。
类似的东西:
if(User.IsInRole("public"))
{
<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.com/analytics.js', 'ga');
ga('create', 'PUBLIC', 'auto');
ga('send', 'pageview');
</script>
}
else if (User.IsInRole("private"))
{
<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.com/analytics.js', 'ga');
ga('create', 'PRIVATE', 'auto');
ga('send', 'pageview');
</script>
}
答案 0 :(得分:2)
您正在寻找User ID feature。这是Tutorial。
您需要setup该功能。然后你可以像这样开始跟踪:
Id RepairCost BikeNumber
16 82 23
88 51 20
12 20 19
33 22 **18**
40 58 **18**
69 41 17
10 2 16
66 35 15
您可以通过
检测的匿名用户ga('create', 'UA-XXXXXX-Y', {'userId': customUserId});
您希望向匿名用户发送您没有User.Identity.IsAuthenticated
的用户ID。
答案 1 :(得分:0)
我已经测试了几天了,我找到了在同一个帐户中拥有2个不同属性的好方法:
@if (Model.IsUserInternal == true)
{
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXXX-2', 'auto');
ga('send', 'pageview');
</script>
}
else
{
<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.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXXXXX-1', 'auto');
ga('send', 'pageview');
</script>
}
XXXXXXXXX是相同的。