File: analytics.cs

package info (click to toggle)
gdata-sharp 2.2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 12,092 kB
  • sloc: cs: 67,781; xml: 38,234; python: 163; makefile: 149; sh: 27
file content (92 lines) | stat: -rw-r--r-- 3,032 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Google.GData.Analytics;
using Google.GData.Extensions;

namespace Analytics
{
    public partial class Analytics : Form
    {
        public Analytics()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Analytics());
        }

        private void Go_Click(object sender, System.EventArgs e)
        {
            RefreshFeed();
        }

        private void RefreshFeed()
        {
            string userName = this.Username.Text;
            string passWord = this.Password.Text;

            AccountQuery query = new AccountQuery();
            AnalyticsService service = new AnalyticsService("AnalyticsSampleApp");
            if (!string.IsNullOrEmpty(userName))
            {
                service.setUserCredentials(userName, passWord);
            }

            AccountFeed accountFeed = service.Query(query);
            foreach (AccountEntry entry in accountFeed.Entries)
            {
                ListViewItem item = new ListViewItem(entry.Title.Text);
                //item.SubItems.Add(entry.Title.Text);
                item.SubItems.Add(entry.ProfileId.Value);
                this.ProfileIds.Items.Add(item);
            }
        }

        private void GoGet_Click(object sender, EventArgs e)
        {
            PageviewFeed();
        }

        private void PageviewFeed()
        {
            string userName = this.Username.Text;
            string passWord = this.Password.Text;
            string profileId = this.ProfileIds.SelectedItems[0].SubItems[1].Text;
            const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";

            AnalyticsService service = new AnalyticsService("AnalyticsSampleApp");
            if (!string.IsNullOrEmpty(userName))
            {
                service.setUserCredentials(userName, passWord);
            }

            DataQuery query = new DataQuery(dataFeedUrl);
            query.Ids = profileId;
            query.Metrics = "ga:pageviews";
            query.Dimensions = "ga:browser";
            query.Sort = "ga:browser,ga:pageviews";
            query.GAStartDate = DateTime.Now.AddDays(-14).ToString("yyyy-MM-dd");
            query.GAEndDate = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd");

            DataFeed dataFeed = service.Query(query);
            foreach (DataEntry entry in dataFeed.Entries)
            {
                ListViewItem item = new ListViewItem(entry.Title.Text);
                item.SubItems.Add(entry.Metrics[0].Value);
                this.ListPageviews.Items.Add(item);
            }
        }
    }
}