简体   繁体   English

如何跟踪从请求(asp.net mvc3)收到的Google Analytics(分析)文件?

[英]How to track files received from Request (asp.net mvc3) for Google Analytics?

I'm using ASP.NET MVC3 C# and I wrote in model a method which takes the files and archive them in a ZIP format like: 我正在使用ASP.NET MVC3 C#,并在模型中编写了一种方法,该方法采用文件并将其归档为ZIP格式,例如:

HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader( "content-disposition", "filename=" + myFilename );

 ZipForge zip = new ZipForge();
    try {
       zip.FileName = Path.Combine( folder, myFilename );
       zip.OpenArchive( System.IO.FileMode.Create );
       zip.BaseDir = Path.GetPathRoot( aPath );
       zip.Options.StorePath = StorePathMode.NoPath;

       zip.AddFiles( file1 );
       zip.AddFiles( file2 );

       zip.CloseArchive();

       HttpContext.Current.Response.WriteFile( zip.FileName );

    } catch {}

The ZIP file is wrote on Request and send back to original page where someone pressed on Download button. 该ZIP文件将写在“请求”上,然后发送回原始页面,在此页面上有人按下“ Download按钮。

I want to track this ZIP file for Google Analytics. 我想为Google Analytics(分析)跟踪此ZIP文件。

How to do that in this case ? 在这种情况下该怎么做?

I read http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55529 but in my case is too complicate. 我阅读了http://support.google.com/googleanalytics/bin/answer.py?hl=zh_CN&answer=55529,但我的情况太复杂了。

I have to use a Javascript object in Controller ? 我必须在Controller中使用Javascript对象吗?

I need an advice Thank you 我需要一个建议谢谢

I read http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55529 but in my case is too complicate. 我阅读了http://support.google.com/googleanalytics/bin/answer.py?hl=zh_CN&answer=55529,但我的情况太复杂了。

Why? 为什么? Simply generate the link that is pointing to your download controller action as explained in the article: 只需生成指向您的下载控制器操作的链接,如文章中所述:

@Html.ActionLink(
    "download file", 
    "download", 
    "home", 
    null, 
    new { 
        onclick = "javascript: _gaq.push(['_trackPageview', '" + Url.Action("download", "home") + "']);" 
    }
)

or do it unobtrusively: 或毫不客气地做:

@Html.ActionLink(
    "download file", 
    "download", 
    "home", 
    null, 
    new { 
        id = "mydownloadlink"
    }
)

and then in a separate javascript file: 然后在一个单独的javascript文件中:

$(function() {
    $('#mydownloadlink').click(function() {
        _gaq.push(['_trackPageview', this.href]);
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM