Exemplo n.º 1
0
function createDigest(&$analytics)
{
    try {
        // Step 2. Get the user's first view (profile) ID.
        $profileId = '7631145';
        if (isset($profileId)) {
            $yesterday = new DateTime();
            $yesterday->sub(new DateInterval('P1D'));
            $yesterday_pageviews = pageviewsForDates($analytics, $profileId, $yesterday->format('Y-m-d'), $yesterday->format('Y-m-d'));
            $yesterday->sub(new DateInterval('P1D'));
            $lastweek = new DateTime();
            $lastweek->sub(new DateInterval('P8D'));
            $lastweek_pageviews = pageviewsForDates($analytics, $profileId, $lastweek->format('Y-m-d'), $lastweek->format('Y-m-d'));
            $message = "DAILY DIGEST: Yesterday (" . $yesterday->format('l') . "), we did <https://www.google.com/analytics/web/?hl=en#report/visitors-overview/" . GOOGLE_ANALYTICS_WEB_ID . "/%3F_u.date00%3D" . $yesterday->format('Ymd') . "%26_u.date01%3D" . $yesterday->format('Ymd') . "%26overview-graphOptions.selected%3Danalytics.nthHour/|" . floor($yesterday_pageviews / 1000) . "k pageviews>. Last " . $lastweek->format('l') . ", we did <https://www.google.com/analytics/web/?hl=en#report/visitors-overview/" . GOOGLE_ANALYTICS_WEB_ID . "/%3F_u.date00%3D" . $lastweek->format('Ymd') . "%26_u.date01%3D" . $lastweek->format('Ymd') . "%26overview-graphOptions.selected%3Danalytics.nthHour/|" . floor($lastweek_pageviews / 1000) . "k pageviews> (" . ($yesterday_pageviews - $lastweek_pageviews > 1000 ? "+" : "") . floor(($yesterday_pageviews - $lastweek_pageviews) / 1000) . "k).";
            // Step 4. Output the results.
            slackMessage($message, "#general");
            slackMessage($message, "#analytics");
        }
    } catch (apiServiceException $e) {
        // Error from the API.
        print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();
    } catch (Exception $e) {
        print 'There wan a general error : ' . $e->getMessage();
    }
}
function createDigest(&$analytics)
{
    try {
        // Step 2. Get the user's first view (profile) ID.
        $profileId = GOOGLE_ANALYTICS_PROFILE_ID;
        if (isset($profileId)) {
            $totalActiveUsers = totalActiveUsers($analytics, $profileId);
            $pagePaths = pagePath($analytics, $profileId);
            $pagePaths = array_reverse($pagePaths);
            $topPosts = '';
            $count = 0;
            for ($count = 0; $count <= 6; $count++) {
                if (strcmp($pagePaths[$count][0], '/') !== 0) {
                    $topPosts .= "\n<https://www.google.com/analytics/web/?hl=en#realtime/rt-content/" . GOOGLE_ANALYTICS_WEB_ID . "/%3Ffilter.list%3D10%3D%3D" . urlencode($pagePaths[$count][0]) . "|" . $pagePaths[$count][1] . ">\t<" . YOUR_DOMAIN . $pagePaths[$count][0] . "|" . str_replace(".html", "", preg_replace('/\\/\\d+\\/\\d+\\/\\d+\\//', '', $pagePaths[$count][0])) . ">";
                }
            }
            $message = "Current users on the site: <https://www.google.com/analytics/web/?hl=en#realtime/rt-overview/" . GOOGLE_ANALYTICS_WEB_ID . "/|{$totalActiveUsers}>\n\nTop posts:\n" . $topPosts;
            // echo $message;
            // Step 4. Output the results.
            // slackMessage($message, "#general");
            slackMessage($message, "#analytics");
        }
    } catch (apiServiceException $e) {
        // Error from the API.
        print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();
    } catch (Exception $e) {
        print 'There was a general error : ' . $e->getMessage();
    }
}
Exemplo n.º 3
0
function createDigest(&$analytics)
{
    try {
        // Step 2. Get the user's first view (profile) ID.
        $profileId = GOOGLE_ANALYTICS_PROFILE_ID;
        if (isset($profileId)) {
            $yesterday = new DateTime();
            $yesterday->sub(new DateInterval('P1D'));
            $yesterday_pageviews = pageviewsForDates($analytics, $profileId, $yesterday->format('Y-m-d'), $yesterday->format('Y-m-d'));
            $yesterday_pageviews_output = PAGEVIEWS_DISPLAY_IN_THOUSANDS ? floor($yesterday_pageviews / 1000) . "k" : $yesterday_pageviews;
            $yesterday->sub(new DateInterval('P1D'));
            $lastweek = new DateTime();
            $lastweek->sub(new DateInterval('P8D'));
            $lastweek_pageviews = pageviewsForDates($analytics, $profileId, $lastweek->format('Y-m-d'), $lastweek->format('Y-m-d'));
            $lastweek_pageviews_output = PAGEVIEWS_DISPLAY_IN_THOUSANDS ? floor($lastweek_pageviews / 1000) . "k" : $lastweek_pageviews;
            $message = "DAILY DIGEST: ";
            $message .= "Yesterday (" . $yesterday->format('l') . "), we did <https://www.google.com/analytics/web/?hl=en#report/visitors-overview/" . GOOGLE_ANALYTICS_WEB_ID . "/%3F_u.date00%3D" . $yesterday->format('Ymd') . "%26_u.date01%3D" . $yesterday->format('Ymd') . "%26overview-graphOptions.selected%3Danalytics.nthHour/|" . $yesterday_pageviews_output . " pageviews>.";
            $message .= " Last " . $lastweek->format('l') . ", we did <https://www.google.com/analytics/web/?hl=en#report/visitors-overview/" . GOOGLE_ANALYTICS_WEB_ID . "/%3F_u.date00%3D" . $lastweek->format('Ymd') . "%26_u.date01%3D" . $lastweek->format('Ymd') . "%26overview-graphOptions.selected%3Danalytics.nthHour/|" . $lastweek_pageviews_output . " pageviews>";
            if (!PAGEVIEWS_DISPLAY_IN_THOUSANDS) {
                $message .= ".";
            } else {
                $message .= " (" . ($yesterday_pageviews - $lastweek_pageviews > 1000 ? "+" : "") . floor(($yesterday_pageviews - $lastweek_pageviews) / 1000) . "k).";
            }
            // Step 4. Output the results.
            slackMessage($message, SLACK_NOTIFICATION_CHANNEL);
        }
    } catch (apiServiceException $e) {
        // Error from the API.
        print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();
    } catch (Exception $e) {
        print 'There wan a general error : ' . $e->getMessage();
    }
}