标签: google-analytics-api

使用Google Analytics将数据显示在我们的网页上?

在我们的某些页面上,我们会显示一些统计信息,例如今天查看该页面的次数,过去一周查看过的次数等.此外,我们还有一个整体统计页面,我们按顺序列出页面,这被认为是最多的.

今天,我们只是将这些综合浏览量和事件计数插入我们的数据库中.我们还会通过常规网页跟踪及其API将其发送给Google Analytics.理想情况下,我们只需查询Google Analytics的API,而不是查询我们的数据库,以便在我们的网页上显示这些统计信息.Google Analytics(分析)可以更好地确定真正的独立用户是谁,并避免计算人为夸大其网页浏览量的人数(我们允许人们在我们的网站上创建网页).

所以问题是,是否可以使用Google Analytics的API更新我们网页的统计信息?如果我缓存结果是否更可行?或者只是偶尔更新我们的统计数据?我非常喜欢谷歌分析我们的网站指标,但也许有一个更好的解决方案,以满足这一特殊需求?

statistics google-analytics visitor-statistic google-analytics-api usage-statistics

6
推荐指数
1
解决办法
1524
查看次数

在Android中,如何在按钮点击时使用Google Analytics事件跟踪

我的目标是使用Google Analytics事件跟踪计算按钮点击次数.

如何计算按钮点击次数以及哪个用户(和设备)点击了此按钮?

我正在使用此代码:

public class TestActivity extends Activity {
GoogleAnalyticsTracker tracker;
Button clickBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.startNewSession("UA-XXXXXXXX-1", 30, this);
    tracker.setDebug(true);

    clickBtn = (Button) findViewById(R.id.click);
    setContentView(R.layout.main);
    final Button createEventButton = (Button) findViewById(R.id.NewEventButton);

    createEventButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tracker.trackEvent("Clicks", // Category
                    "Button", // Action
                    "" + clickBtn, // Label
                    77); // Value
            tracker.trackEvent("Clicks", "" + createEventButton, "Easy", 1);
            tracker.trackEvent("Completions", "Game-Deaths",
                    "Hard-Level-One", 15);
            tracker.trackEvent("Die", "Easy", " Two", 15);
            tracker.trackTransactions();
        }
    }); …
Run Code Online (Sandbox Code Playgroud)

android google-analytics google-analytics-api

6
推荐指数
1
解决办法
1万
查看次数

通过代理服务器路由Google Analytics v3 API

我们正在使用Google Analytics API v3 (点网版)在我们的网站上报告一些统计数据.我的代码在我的本地计算机上正常运行,但由于某些防火墙规则,它无法在生产服务器上运行.我们的系统管理员建议尝试使用代理.我在互联网上搜索了为Google AnalyticsAPI服务设置代理的任何指南,但没有运气.感谢这方面的任何指示.

编辑:

   public DataTable GetSearchTrends()
    {
        string GoogleAnalyticsProfileId = AppConfigManager.GetGoogleAnalyticsProfileIdForInis();

        var service = new AnalyticsService(new BaseClientService.Initializer()
        {
            Authenticator = Authenticate()

        });

            DataResource.GaResource.GetRequest request = service.Data.Ga.Get(
            GoogleAnalyticsProfileId,
            string.Format("{0:yyyy-MM-dd}", StartDate),
            string.Format("{0:yyyy-MM-dd}", EndDate),
            GoogleAnalyticsSearchUniquesMetric
            );

        request.Dimensions = GoogleAnalyticsSearchKeywordMetric;
        request.Sort = string.Concat("-", GoogleAnalyticsSearchUniquesMetric);
        request.MaxResults = NumberOfSearchTrendsToFetch;

        GaData response = request.Fetch();

        return SearchTrendsHelper.ConvertToDataTable(
            response.Rows,
            SearchTrendsKeywordsExcludeList,
            NumberOfSearchTrendsToDisplay
            );
    }


   private IAuthenticator Authenticate()
    {
        string GoogleAnalyticsServiceScope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();
        string GoogleApiServiceAccountId = AppConfigManager.GetGoogleApiServiceAccountId();
        string GoogleApiServiceAccountKeyFile = AppConfigManager.GetGoogleApiServiceAccountKeyFile();
        string GoogleApiServiceAccountKeyPassword = AppConfigManager.GetGoogleApiServiceAccountKeyPassword();
        AuthorizationServerDescription …
Run Code Online (Sandbox Code Playgroud)

.net google-api google-analytics-api google-api-dotnet-client

6
推荐指数
1
解决办法
2347
查看次数

Google OAuth令牌错误 - 400次错误请求

我正在尝试使用OAuth2验证我的应用程序并使用"已安装的应用程序"流程(获取auth-code然后请求令牌).我400 bad request error在GetResponse()行上请求令牌时得到了一个.我的代码如下:

Public Sub New()
    Dim tokenRequest As WebRequest = 
         WebRequest.Create("https://accounts.google.com/o/oauth2/token")

    Dim requestString As String = "code=<auth-code>" _
                        & "&client_id=<client_id>" _
                        & "&client_secret=<client_secret>" _
                        & "&redirect_uri=http://localhost" _
                        & "&grant_type=authorization_code"

    byteArray = StrToByteArray(System.Web.HttpUtility.UrlEncode(requestString))

    tokenRequest.Credentials = CredentialCache.DefaultCredentials
    tokenRequest.Method = "POST"
    tokenRequest.ContentLength = byteArray.Length
    tokenRequest.ContentType = "application/x-www-form-urlencoded"
    Dim dataStream As Stream = tokenRequest.GetRequestStream()

    dataStream.Write(byteArray, 0, byteArray.Length)
    dataStream.Close()

    Console.WriteLine("Getting response...")

    'Get response
    Try
        Dim response As WebResponse = tokenRequest.GetResponse()

        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)

        Dim data As Stream = response.GetResponseStream

        Array.Resize(byteArray, 4096)

        Array.Clear(byteArray, …
Run Code Online (Sandbox Code Playgroud)

vb.net google-analytics google-analytics-api google-oauth

6
推荐指数
1
解决办法
2372
查看次数

JS Analytics电子商务回调

我找不到任何地方如何使用hitCallback谷歌分析参数ecommerce:send.在文档中,它唯一的例子是send,pageview.

这是我试过的代码:

ga('ecommerce:send',
   {'hitCallback': function() {window.location.href="/test.php";}}
);
Run Code Online (Sandbox Code Playgroud)

但是虽然跟踪有效,但它没有用.

javascript google-analytics google-analytics-api e-commerce

6
推荐指数
1
解决办法
1730
查看次数

如何在PHP中获取谷歌分析实时activeUsers?

我从https://github.com/google/google-api-php-client下载了API文件, 并尝试使用以下代码...

$client->setApplicationName("Analytics");
$client->setDeveloperKey("key");
$service = new Google_Service_Analytics($client);

$optParams = array(
    'dimensions' => 'rt:medium');

try {
  $results = $service->data_realtime->get(
      'ga:profileid',
      'rt:activeUsers',
      $optParams);
  // Success.
} catch (apiServiceException $e) {
  // Handle API service exceptions.
  $error = $e->getMessage();
}
print_r($results);
Run Code Online (Sandbox Code Playgroud)

它显示错误(401)需要登录'

当我通过https://console.developers.google.com/project/apps~rational-photon-578/apiui/api/analytics/method/analytics.data.realtime.get尝试通话时

我得到了所需的实时用户所属的profileid.

那么我该如何实现登录过程(无需访问谷歌网站)呢?

我尝试了以下代码......

$client_id              = 'xxxxxxxxxxxxxxx';
$service_account_name   = 'xxxxxxxxxxxxxxxx@developer.gserviceaccount.com';
$key_file_location      = 'location of .p12 keyfile';

$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");

if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/analytics'),
$key …
Run Code Online (Sandbox Code Playgroud)

php google-api google-analytics-api oauth-2.0 google-oauth

6
推荐指数
1
解决办法
3979
查看次数

Google OAuth 2.0 Server to Server:错误的请求

现在我已经在墙上敲了3天,试图让它发挥作用.

POST /oauth2/v3/token HTTP/1.1
Host: www.googleapis.com
Content-length: 495
Content-type: application/x-www-form-urlencoded
Authorization: Bearer ya29.cgEcY6meBrvaH6oe0nD_PtsFyMVqskiUYi7iJxapKHeEgPoIw8gMt0BJdIvRn1MfcEgzTS3_gTwI1w
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5MDgyOTgxNjA1NTktc2R1bGFpbWhsaGpxOTY5M2s1Z2E4c25pZjhh%0D%0ANzhlZ3BAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0%0D%0AdHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvYW5hbHl0aWNzLnJlYWRvbmx5%0D%0AIiwiYXVkIjoiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tL28vb2F1dGgyL3Rv%0D%0Aa2VuIiwiZXhwIjoxNDMxNTE0MDUyLCJpYXQiOjE0MzE1MTEwNTJ9.[Cert]

HTTP/1.1 400 Bad Request
Content-length: 67
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
Expires: Wed, 13 May 2015 10:08:00 GMT
Vary: Origin,X-Origin
Server: GSE
Cache-control: private, max-age=0
Date: Wed, 13 May 2015 10:08:00 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json; charset=UTF-8
{
  "error_description": "Bad Request", 
  "error": "invalid_grant"
}
Run Code Online (Sandbox Code Playgroud)

所以,我在PL/SQL中创建它.Oracle 12c.我已经设法获得JWT标头和JWT Claim设置生成与google文档相同的输出.当我创建证书时,我认为是问题发生.

  1. 我需要"[----- BEGIN PRIVATE KEY -----"和----- END PRIVATE KEY ----- \n]作为SHA-256加密的一部分.我应该对"新行"做些什么吗?\n我应该用括号括起来吗?

  2. 我应该在什么时候进行URL编码?

  3. 以下示例中的代码是否足以用于加密?:http://jastraub.blogspot.co.uk/2009/07/hmacsha256-in-plsql.html

  4. 我已经附上了下面的功能,看看你是否可以发现任何问题?

谢谢你的帮助!

  FUNCTION get_JWT …
Run Code Online (Sandbox Code Playgroud)

plsql google-analytics-api google-oauth service-accounts oracle12c

6
推荐指数
1
解决办法
1076
查看次数

Google Analytics(分析)API:如何提取帐户,在发生非对象错误时获取listManagementAccounts()

编辑 -本教程(尽管几乎类似于google的教程)才使一切正常:http : //teev.io/blog/google-analytics-api-php

我正在尝试遵循此处提到的教程:https : //developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php

我已经完成了所有步骤:

  1. 创建了一个项目。
  2. 创建了一个服务帐户。(当提示输入JSON或P12时,我选择了JSON)
  3. 我碰composer require google/apiclient:^2.0腻了并更新了composer.json文件。
  4. 将我service-account-credentials.json刚刚下载的文件放入文件夹/public_html
  5. 创建文件HelloAnalytics.php并将其放入/public_html文件夹。

HelloAnalytics.php:

<?php

// Load the Google API PHP Client Library.
require_once '/home/user/vendor/autoload.php';

$analytics = initializeAnalytics();
$profile = getFirstProfileId($analytics);
$results = getResults($analytics, $profile);
printResults($results);

function initializeAnalytics()
{
    // Creates and returns the Analytics Reporting service object.

    // Use the developers console and download your service account
    // credentials in JSON format. Place them in this …
Run Code Online (Sandbox Code Playgroud)

php api google-analytics google-api google-analytics-api

6
推荐指数
2
解决办法
885
查看次数

在API v4(python)中设置最大结果

在API的第3版中,我看到有一个max-results参数可以传递以获得超过1000条记录.我无法弄清楚如何使用python在API的v4中传递该参数.

我的代码如下所示.我已经在max_result上评论了我最好的猜测.

def get_report(analytics):
  # Use the Analytics Service Object to query the Analytics Reporting API V4.
  return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          #'max_results': 100000,
          'dateRanges': [{'startDate': '2016-04-01', 'endDate': '2016-08-09'}],
          'dimensions': [{'name':'ga:date'},
                    {'name': 'ga:channelGrouping'}],
          'metrics': [{'expression': 'ga:sessions'},
                 {'expression': 'ga:newUsers'},
                 {'expression': 'ga:goal15Completions'},
                 {'expression': 'ga:goal9Completions'},
                 {'expression': 'ga:goal10Completions'}]
        }]
      }
  ).execute()
Run Code Online (Sandbox Code Playgroud)

python google-analytics google-analytics-api google-analytics-firebase

6
推荐指数
1
解决办法
2491
查看次数

来自Google Analytics API的Firebase数据

我们如何通过Google Analytics(分析)API获取Firebase数据?通常,APP数据位于Google Analytics(分析)媒体资源中,并且可以通过Google Analytics(分析)View ID获取数据。不幸的是,Google假定现在在Firebase上进行应用程序跟踪。我们如何通过Google表格上的Google Analytics API(核心API)获取Firebase数据?

google-analytics google-sheets google-analytics-api firebase

6
推荐指数
1
解决办法
689
查看次数