如果发生(崩溃和)异常,Google Analytics会向我发送电子邮件吗?

时间:2015-11-03 13:09:57

标签: google-analytics

Google Analytics 正确报告我的Android应用引发的异常。我可以使用预定电子邮件将此报告发送给我。但是,在没有任何要报告的情况下收到每日电子邮件(即报告告诉我发生了零例外)是单调乏味的。因此,我希望仅在有报告内容时才收到电子邮件(即报告告诉我发生了一个或多个例外)。似乎自定义警报可用于此目的。但是,自定义警报似乎与例外不兼容。这引出了我的问题。

是否可以将自定义提醒配置为提供有关例外的电子邮件通知?

或者,更一般地说,

是否可以将Google Analytics配置为提供有关例外的电子邮件通知?

此外,这也适用于崩溃吗?

更新(2015年11月22日,2015年12月1日)

(部分)回答。我提供了an answer,可以将服务器(而不是Google Analytics)配置为提供有关例外的电子邮件通知,这可能是许多人的充分解决方案。

(差不多)回答jakub-kriz提供了detailed answer,但它不能按原样运行。在答案的基础上,我能够在没有异常发生时将Google Analytics配置为电子邮件。这与要求完全相反。不幸的是,当发生一个或多个异常时,我无法收到电子邮件。

替代方向jakub-kriz提出了alternative solution,其中使用了正常事件,而不是异常事件。我没有尝试过这个方向。

尚未提出完整的解决方案。

3 个答案:

答案 0 :(得分:9)

这是可能的,但不是直接的,你必须把你的分析弄得很脏。

1)Analytics Admin中的配置

在Admin中创建两个过滤器 - >查看 - >过滤器 - >自定义 - >先进

创建侦听hitType异常并设置事件类别 - 异常

的过滤器

Filter hitType to Event Category

创建将异常描述复制到事件操作

的过滤器

enter image description here

2)创建自定义目标

在Admin中创建两个过滤器 - >查看 - >目标 - >自定义 - >事件

事件类别等于例外

Event Category equals Exception

3)创建自定义警报

目标包含异常的自定义提醒

Custom alert by Goal containg exception

不要忘记您的电子邮件

enter image description here

试试这个让我知道!

答案 1 :(得分:0)

要获取有关Mail Id的报告,无法直接从Google Analytics中发送。我们可以发送此错误报告来处理它并以编程方式将其发送到我们的应用程序的邮件ID。

答案 2 :(得分:0)

可以将服务器(而非Google Analytics)配置为提供有关例外的电子邮件通知,这对许多人来说可能是一个充分的解决方案。

首先,您需要一个服务帐户,可以创建https://console.developers.google.com/project/_/apiui/credential。您将创建一个密钥文件(MyAnalytics.p12)。

其次,我们配置了分析客户端(MyAnalytics.php):

<?php
//You'll need to install google-api-php-client 
//(https://github.com/google/google-api-php-client)
require_once 'Google/autoload.php';

class MyAnalytics
{
    //When logged into Google Analytics you'll have a URL that looks
    //something like https://www.google.com/analytics/web/?authuser=0#home/a00w11p22/
    //Your profile id is everything after the p
    const PROFILE_ID = '22';

    //This is the service account email that you constructed in step 1
    const SERVICE_ACCOUNT_EMAIL = 'blah@developer.gserviceaccount.com';

    //This is the file that you constructed in step 1.
    const KEY_FILE_LOCATION = 'MyAnalytics.p12';

    private $client;
    private $analytics;
    private $cred;

    public function __construct() {
        $this->client = new Google_Client();
        $this->analytics = new Google_Service_Analytics($this->client);
        $key = file_get_contents(self::KEY_FILE_LOCATION);

        $this->cred = new Google_Auth_AssertionCredentials(
          self::SERVICE_ACCOUNT_EMAIL,
          array(Google_Service_Analytics::ANALYTICS_READONLY),
          $key
        );
    }

    public function getAnalytics() {
        $this->client->setAssertionCredentials($this->cred);

        if($this->client->getAuth()->isAccessTokenExpired()) {
           $this->client->getAuth()->refreshTokenWithAssertion($this->cred);
        }

        return $this->analytics;
    }
}

?>

第三,我们查询和报告异常(exceptions.php):

<?php
    require_once 'MyAnalytics.php';

    $myAnalytics = new MyAnalytics();
    $analytics = $myAnalytics->getAnalytics();

    $results = $analytics->data_ga->get(
         'ga:' . MyAnalytics::PROFILE_ID,
         'yesterday',
         'today',
         'ga:exceptions'
    );

    $a = $results->getTotalsForAllResults();
    $count = $a['ga:exceptions'];

    echo $count;

    if (is_numeric($count) && $count > 0) {
        //handle the exception, e.g., send an email
        //(cf. https://stackoverflow.com/a/5335311/3664487)
    }       
?>

第四,配置cron运行exceptions.php(参见https://stackoverflow.com/a/22358929/3664487)。