예제 #1
0
        public List<SiteEvent> getEventData(DateTime fromDate, DateTime toDate, Site site)
        {
            List<SiteEvent> events = new List<SiteEvent>();

            int startIndex = 1;
            Boolean isMore;

            DataFeed feed = null;
            do
            {
                isMore = false;

                try
                {

                    feed = getGADataFeed(site, fromDate, toDate,
                                        "ga:eventCategory,ga:eventAction,ga:eventLabel,ga:date",
                                        "ga:totalEvents,ga:uniqueEvents",
                                        "ga:eventCategory==Availability,ga:eventCategory==Search,ga:eventAction==Click", "", startIndex);

                    if (feed != null)
                    {
                        foreach (DataEntry singleEntry in feed.Entries)
                        {
                            SiteEvent siteEvent = new SiteEvent(singleEntry, site);
                            events.Add(siteEvent);
                            isMore = true;
                        }
                    }
                }
                catch (Exception rEx)
                {
                    log.Error("Error in getEventData", rEx);
                }

                if (isMore) startIndex += numberOfGARecordsToRetrievePerRequest;
            } while (isMore);

            return events;
        }
        public void recordAnalyticsEvent(SiteEvent siteEvent)
        {
            SqlConnection conn = new SqlConnection(connectionAnalytics);

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = @"IF NOT EXISTS(SELECT (1) FROM Analytics_Event (nolock) WHERE Analytics_Date = @Date AND Site = @Account AND Category = @Category AND Action = @Action AND Label = @Label)
                                        INSERT INTO Analytics_Event (Analytics_Date, Site, Category, Action, Label, TotalEvents, UniqueEvents)
                                            VALUES (@Date, @Account, @Category, @Action, @Label, @TotalEvents, @UniqueEvents)
                                    ELSE
                                        UPDATE Analytics_Event
                                        SET TotalEvents = @TotalEvents,
                                            UniqueEvents = @UniqueEvents
                                        WHERE Analytics_Date = @Date AND Site = @Account AND Category = @Category AND Action = @Action AND Label = @Label";

                cmd.Parameters.Add("@Date", SqlDbType.DateTime);
                cmd.Parameters["@Date"].Value = siteEvent.gaDate;

                cmd.Parameters.Add("@Account", SqlDbType.NVarChar);
                cmd.Parameters["@Account"].Value = truncate(siteEvent.gaAccount, 15);

                cmd.Parameters.Add("@Category", SqlDbType.NVarChar);
                cmd.Parameters["@Category"].Value = truncate(siteEvent.category, 50);

                cmd.Parameters.Add("@Action", SqlDbType.NVarChar);
                cmd.Parameters["@Action"].Value = truncate(siteEvent.action, 50);

                cmd.Parameters.Add("@Label", SqlDbType.NVarChar);
                cmd.Parameters["@Label"].Value = truncate(siteEvent.label, 255);

                cmd.Parameters.Add("@TotalEvents", SqlDbType.Int);
                cmd.Parameters["@TotalEvents"].Value = siteEvent.totalEvents;

                cmd.Parameters.Add("@UniqueEvents", SqlDbType.Int);
                cmd.Parameters["@UniqueEvents"].Value = siteEvent.uniqueEvents;

                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
            catch (SqlException sqle)
            {
                log.Error("Error in recordAnalyticsEvent", sqle);
            }
            finally
            {
                if (conn != null)
                {
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
        }