public List<Search> getSiteSearchData(DateTime fromDate, DateTime toDate, Site site) { List<Search> searchData = new List<Search>(); int startIndex = 1; Boolean isMore; DataFeed feed = null; do { isMore = false; try { feed = getGADataFeed(site, fromDate, toDate, "ga:visitLength,ga:transactionId,ga:searchUsed", "ga:transactions", "", "", startIndex); if (feed != null) { foreach (DataEntry singleEntry in feed.Entries) { Search search = new Search(singleEntry); searchData.Add(search); isMore = true; } } } catch (Exception rEx) { log.Error("Error in getSiteSearchData", rEx); } if (isMore) startIndex += numberOfGARecordsToRetrievePerRequest; } while (isMore); return searchData; }
public void recordAnalyticsSiteSearch(Search siteSearch) { SqlConnection conn = new SqlConnection(connectionAnalytics); try { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = @"IF NOT EXISTS(SELECT (1) FROM analytics_search (nolock) WHERE TransactionID = @TransactionID) INSERT INTO analytics_search (TransactionID, SiteSearchUsed, VisitLength) VALUES ( @TransactionID, @SiteSearchUsed, @VisitLength) ELSE UPDATE analytics_search SET SiteSearchUsed = @SiteSearchUsed, VisitLength = @VisitLength WHERE TransactionID = @TransactionID"; cmd.Parameters.Add("@VisitLength", SqlDbType.Int); cmd.Parameters["@VisitLength"].Value = siteSearch.visitLength; cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar); cmd.Parameters["@TransactionID"].Value = truncate(siteSearch.orderNumber, 255); cmd.Parameters.Add("@SiteSearchUsed", SqlDbType.Bit); cmd.Parameters["@SiteSearchUsed"].Value = siteSearch.searchUsed; cmd.ExecuteNonQuery(); cmd.Dispose(); } catch (SqlException sqle) { log.Error("Error in recordAnalyticsSiteSearch", sqle); } finally { if (conn != null) { if (conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } } }