在我的网站上显示

在我的网站上显示

本文介绍了在我的网站上显示Google Analytics数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一种方法在我的网站上显示从Google Analytics收集的数据。我使用的是NopCommerce,我想在管理部分的视图中显示这些信息/统计信息。



可能有很多方法可以实现这一点,并且在搜索我发现了一些使用JavaScript的例子,但我找不到一个好的教程。



我也研究过将Google Analytics与C#集成,我发现本示例:
演示项目可以从GitHub下载:



然而,该演示项目似乎不适用于Google网址()已不再使用。

当我使用MVC应用程序时,最好通过应用Google Analytics控制器中的逻辑并将其显示在视图中。或者类似的东西。



谷歌提供了一个查询工具在这里进行实验,所以不应该从Google Analytics中提取数据并在网站上显示数据:



任何人都可以在他们的网站上成功显示Google Analytics数据吗?

解决方案

如果其他人遇到同样的问题,那么我就是这么做的,这个问题几乎可以回答这个问题。

/ p>

以下是API客户端的基本代码,可通过Google服务帐户访问Google Analytics中的数据。



为了使这个应用程序能够工作,在开始编码之前,您需要准备好几件事情。



* Google Analytics(分析)帐户 - 注册后会生成一个跟踪器代码,供您放在每个要跟踪的网页上。您可能无法立即看到任何统计信息,并且可能需要最多24小时才能在Google Analytics信息中心显示任何统计信息。



OAuth授权(API-Key) CLIENT_ID,CLIENT SECRET和EMAIL ADRESS(这不是您的正常电子邮件,而是您创建OAuth授权时为您创建的服务帐户电子邮件)。
console.developers.google.com /



一个serverkey,也可以在这里创建:console.developers.google.com/。
您也可以创建一个浏览器密钥,但没有打扰过它,并且不知道它是什么。



最后,您需要一个证书密钥。您的应用程序只能使用密钥和凭据访问您的Google Analytics帐户。密钥是一个加密的p.12文件。您可以在



2。

现在您已拥有所有需要的密钥和凭证,现在可以开始查看以1链接的代码了。以下是再次提供的基本信息:



创建一个控制台应用程序并实现上面的代码。



请注意:您没有创建Google Plus服务,因此您必须更改AnalyticsService的这些部分。转到管理nuget并安装软件包:


  • Google Apis核心库

  • Google Apis客户端库

  • Google Apis认证客户端库

  • Google Apis Analytics.v3库

  • Google GData客户端用于查询数据,指标,等等)

  • Google GData扩展库

  • 分析



可能会忘记一些东西,但这里是我使用的命名空间:

  using System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;

使用System.Security.Cryptography.X509Certificates;
使用Google.Apis.Auth.OAuth2;
使用Google.Apis.Services;
使用Google.Apis.Analytics.v3;

3



借助此功能,我可以访问和查询来自Google Analytics帐户的数据。最好的部分是,您不必登录Google就可以直接访问帐户数据。



我将迁移此项代码到MVC现在我可能会稍后进行更新,以了解如何在Mvc中实现此Analytics客户端。


I'm trying to figure out a way to display data collected from Google Analytics on my web site. I'm using NopCommerce, and I want to display this information/statistics in a view in the Admin Section.

There might be many ways to achieve this, and after searching the web I found some examples using JavaScript, but I couldn't find a good tutorial for this.

I have also looked into integrating Google Analytics with C#, and I found this example: http://biasecurities.com/2012/02/using-the-google-analytics-api-with-asp-net-mvc/#comment-1310A demo project can be downloaded from GitHub here: https://github.com/jgeurts/Analytics-Example

However the demo project doesn't seem to work as the google URL (https://www.google.com/analytics/feeds/accounts/default) is no longer in use.

As I'm using a MVC application it would be preferable to make this happen by applying the Google Analytics logic within a Controller and displaying it in a view. Or something like that.

Google provides a query tool to experiment with here, so it shouldn't be to hard extracting data from Google Analytics and display the data on the website: https://ga-dev-tools.appspot.com/explorer/

Has anyone been able to successfully display Google Analytics data on their website?

解决方案

In case some one else is having the same problem here's what I did and it pretty much answers the question.

1.

Here is the basic code for a API client that access data from Google Analytics via your Google Service Account. https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#service_account

In order to make this application work you need to have several things ready before you start coding.

*Google Analytics Account - once registered a "tracker" code is generated for you to put on each webpage you want to track. You may not see any statistics right away and it can take up to 24h before any statistics are shown in the Google Analytics Dashboard.

An OAuth Authorisation (API-Key) with CLIENT_ID, CLIENT SECRET and EMAIL ADRESS (This is not your normal email but a service account email that is created for you when you make an OAuth Authorisation).console.developers.google.com/

A serverkey, can also be created here: console.developers.google.com/.You can also create a browser key, haven't bothered with that though and don't know what it does.

Finally you need a certificate key. Your application will only be able to access your Google Analytics account by using the key and credentials. The key is an encrypted p.12 file. You can find the key in https://code.google.com/apis/console/.

Here is a guide for the key: http://www.pimcore.org/wiki/display/PIMCORE/Setup+Google+Analytics+Reporting+with+OAuth2+Service+Accounts+(since+1.4.6)

2.

Now that you have all keys and credentials you need it is time to start looking at the code I linked in "1". Here is the basic for it again: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#service_account

Create a console application and implement the code above.

Note: your not making a "Google Plus service" so you have to change those parts for "AnalyticsService". Go to manage nuget and install packages:

  • Google Apis Core Library
  • Google Apis Client Library
  • Google Apis Auth Client Library
  • Google Apis Analytics.v3 Library
  • Google GData Client (This provides properties used to query data, metrics, demensions etc)
  • Google GData Extensions Library
  • Analytics

Might forgot something but here are the namespaces I use:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Analytics.v3;

3

Finally, here's is some of my code. Note I'm creating a new Analytics as supposed to "new ServiceAccountCredentials" as in the code from Google. That's the main difference:Retrieve data from Google Analytics API with .NET, multiple metrics?

With this I'm able to access and query data from Google Analytics account. The best part is that you don't have to log in to Google for this as the key and credentials gives you access to the account data directly.

I will migrate this code to MVC now I might make an update later on for how to implement this Analytics client in Mvc.

这篇关于在我的网站上显示Google Analytics数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 14:22