Ejemplo n.º 1
0
        public List<Visitor> getVisitorData(DateTime fromDate, DateTime toDate, Site site)
        {
            List<Visitor> visitors = new List<Visitor>();

            int startIndex = 1;
            Boolean isMore;

            DataFeed feed = null;
            do
            {
                isMore = false;

                try
                {

                    feed = getGADataFeed(site, fromDate, toDate,
                                        "ga:daysSinceLastVisit,ga:pageDepth,ga:visitCount,ga:visitorType,ga:landingPagePath,ga:transactionId",
                                        "ga:transactions",
                                        "", "", startIndex);

                    if (feed != null)
                    {
                        foreach (DataEntry singleEntry in feed.Entries)
                        {
                            Visitor visitor = new Visitor(singleEntry);
                            visitors.Add(visitor);
                            isMore = true;
                        }
                    }
                }
                catch (Exception rEx)
                {
                    log.Error("Error in getVisitorData", rEx);
                }

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

            return visitors;
        }
        public void recordAnalyticsVisitor(Visitor visitor)
        {
            SqlConnection conn = new SqlConnection(connectionAnalytics);

            try
            {
                conn.Open();

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

                cmd.CommandText = @"IF NOT EXISTS(SELECT (1) FROM analytics_visitor (nolock) WHERE TransactionID = @TransactionID)
                                        INSERT INTO analytics_visitor (LandingPagePath, TransactionID, DaysSinceLastVisit, PageDepth, VisitCount, IsNewVisitor)
                                            VALUES (@LandingPagePath, @TransactionID, @DaysSinceLastVisit, @PageDepth, @VisitCount, @IsNewVisitor)
                                    ELSE
                                        UPDATE analytics_visitor
                                        SET LandingPagePath = @LandingPagePath,
                                            DaysSinceLastVisit = @DaysSinceLastVisit,
                                            PageDepth = @PageDepth,
                                            VisitCount = @VisitCount,
                                            IsNewVisitor = @IsNewVisitor
                                        WHERE TransactionID = @TransactionID";

                cmd.Parameters.Add("@LandingPagePath", SqlDbType.NVarChar);
                cmd.Parameters["@LandingPagePath"].Value = truncate(visitor.landingPagePath, 255) ;

                cmd.Parameters.Add("@DaysSinceLastVisit", SqlDbType.Int);
                cmd.Parameters["@DaysSinceLastVisit"].Value = visitor.daysSinceLastVisit;

                cmd.Parameters.Add("@PageDepth", SqlDbType.Int);
                cmd.Parameters["@PageDepth"].Value = visitor.pageDepth;

                cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar);
                cmd.Parameters["@TransactionID"].Value = truncate(visitor.orderNumber, 255);

                cmd.Parameters.Add("@VisitCount", SqlDbType.Int);
                cmd.Parameters["@VisitCount"].Value = visitor.visitCount;

                cmd.Parameters.Add("@IsNewVisitor", SqlDbType.Bit);
                cmd.Parameters["@IsNewVisitor"].Value = visitor.isNewVisitor;

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