0

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:

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.

I want to track this ZIP file for Google Analytics.

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.

I have to use a Javascript object in Controller ?

I need an advice Thank you

4

1 に答える 1

0

http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55529を読み ましたが、私の場合は複雑すぎます。

なんで?記事で説明されているように、ダウンロードコントローラーのアクションを指すリンクを生成するだけです。

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

または目立たないようにします。

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

次に、別のjavascriptファイルで:

$(function() {
    $('#mydownloadlink').click(function() {
        _gaq.push(['_trackPageview', this.href]);
    });
});
于 2012-05-04T08:05:16.270 に答える