Пример #1
0
        static void TestET_SentEvent()
        {

            DateTime filterDate = new DateTime(2013, 1, 15, 13, 0, 0);

            Console.WriteLine("--- Testing SentEvent ---");
            ET_Client myclient = new ET_Client();

            Console.WriteLine("Retrieve Filtered SentEvents with GetMoreResults");
            ET_SentEvent oe = new ET_SentEvent();
            oe.AuthStub = myclient;
            oe.SearchFilter = new SimpleFilterPart() { Property = "EventDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new DateTime[] { filterDate } };
            oe.Props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" };
            GetReturn oeGet = oe.Get();

            Console.WriteLine("Get Status: " + oeGet.Status.ToString());
            Console.WriteLine("Message: " + oeGet.Message.ToString());
            Console.WriteLine("Code: " + oeGet.Code.ToString());
            Console.WriteLine("Results Length: " + oeGet.Results.Length);
            Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString());
            // Since this could potentially return a large number of results, we do not want to print the results
            //foreach (ET_SentEvent SentEvent in oeGet.Results)
            //{
            //    Console.WriteLine("SubscriberKey: " + SentEvent.SubscriberKey + ", EventDate: " + SentEvent.EventDate.ToString());
            //}

            while (oeGet.MoreResults)
            {
                Console.WriteLine("Continue Retrieve Filtered SentEvents with GetMoreResults");
                oeGet = oe.GetMoreResults();
                Console.WriteLine("Get Status: " + oeGet.Status.ToString());
                Console.WriteLine("Message: " + oeGet.Message.ToString());
                Console.WriteLine("Code: " + oeGet.Code.ToString());
                Console.WriteLine("Results Length: " + oeGet.Results.Length);
                Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString());
            }


            //The following request could potentially bring back large amounts of data if run against a production account	
            //Console.WriteLine("Retrieve All SentEvents with GetMoreResults");
            //ET_SentEvent oe = new ET_SentEvent();
            //oe.authStub = myclient;
            //oe.props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" };
            //GetResponse oeGetAll = oe.Get();

            //Console.WriteLine("Get Status: " + oeGetAll.Status.ToString());
            //Console.WriteLine("Message: " + oeGetAll.Message.ToString());
            //Console.WriteLine("Code: " + oeGetAll.Code.ToString());
            //Console.WriteLine("Results Length: " + oeGetAll.Results.Length);
            //Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString());
            //// Since this could potentially return a large number of results, we do not want to print the results
            ////foreach (ET_SentEvent SentEvent in oeGet.Results)
            ////{
            ////    Console.WriteLine("SubscriberKey: " + SentEvent.SubscriberKey + ", EventDate: " + SentEvent.EventDate.ToString());
            ////}

            //while (oeGetAll.MoreResults)
            //{
            //    oeGetAll = oe.GetMoreResults();
            //    Console.WriteLine("Get Status: " + oeGetAll.Status.ToString());
            //    Console.WriteLine("Message: " + oeGetAll.Message.ToString());
            //    Console.WriteLine("Code: " + oeGetAll.Code.ToString());
            //    Console.WriteLine("Results Length: " + oeGetAll.Results.Length);
            //    Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString());
            //}
        }
        public IEnumerable<IMetricsProvider> GetMetrics(int days)
        {
            Dictionary<int, ProviderMetrics> dictionary = new Dictionary<int,ProviderMetrics>();

            ///////////////////////////////////////////////////////////////////
            //
            // setup variables used throughout the routine
            //
            ///////////////////////////////////////////////////////////////////

            ET_Client client = CreateClient();

            string[] properties = new string[]
            {
                "EventDate",
                "SendID",
            };

            DateTime end = DateTime.Now;
            DateTime start = end - TimeSpan.FromDays(days);

            SimpleFilterPart filter = new SimpleFilterPart();
            filter.Property = "EventDate";
            filter.SimpleOperator = SimpleOperators.between;
            filter.DateValue = new DateTime[] { start, end };

            ///////////////////////////////////////////////////////////////////
            //
            // count bounces
            //
            ///////////////////////////////////////////////////////////////////

            ET_BounceEvent bounce = new ET_BounceEvent();
            bounce.GetSinceLastBatch = false;
            bounce.AuthStub = client;
            bounce.SearchFilter = filter;
            bounce.Props = properties;

            GetReturn results = bounce.Get();

            foreach (ET_BounceEvent item in results.Results)
            {
                if (!dictionary.ContainsKey(item.SendID))
                {
                    dictionary[item.SendID] = new ProviderMetrics();
                    dictionary[item.SendID].Name = GetEmailName(client, item.SendID);
                }

                dictionary[item.SendID].Bounces++;
            }

            ///////////////////////////////////////////////////////////////////
            //
            // count clicks
            //
            ///////////////////////////////////////////////////////////////////

            ET_ClickEvent click = new ET_ClickEvent();
            click.GetSinceLastBatch = false;
            click.AuthStub = client;
            click.SearchFilter = filter;
            click.Props = properties;

            results = click.Get();

            foreach (ET_ClickEvent item in results.Results)
            {
                if (!dictionary.ContainsKey(item.SendID))
                {
                    dictionary[item.SendID] = new ProviderMetrics();
                    dictionary[item.SendID].Name = GetEmailName(client, item.SendID);
                }

                dictionary[item.SendID].Clicks++;
            }

            ///////////////////////////////////////////////////////////////////
            //
            // count opens
            //
            ///////////////////////////////////////////////////////////////////

            ET_OpenEvent open = new ET_OpenEvent();
            open.GetSinceLastBatch = false;
            open.AuthStub = client;
            open.SearchFilter = filter;
            open.Props = properties;

            results = open.Get();

            foreach (ET_OpenEvent item in results.Results)
            {
                if (!dictionary.ContainsKey(item.SendID))
                {
                    dictionary[item.SendID] = new ProviderMetrics();
                    dictionary[item.SendID].Name = GetEmailName(client, item.SendID);
                }

                dictionary[item.SendID].Opens++;
            }

            ///////////////////////////////////////////////////////////////////
            //
            // count sends
            //
            ///////////////////////////////////////////////////////////////////

            ET_SentEvent send = new ET_SentEvent();
            send.GetSinceLastBatch = false;
            send.AuthStub = client;
            send.SearchFilter = filter;
            send.Props = properties;

            results = send.Get();

            foreach (ET_SentEvent item in results.Results)
            {
                if (!dictionary.ContainsKey(item.SendID))
                {
                    dictionary[item.SendID] = new ProviderMetrics();
                    dictionary[item.SendID].Name = GetEmailName(client, item.SendID);
                }

                dictionary[item.SendID].Sends++;
            }

            ///////////////////////////////////////////////////////////////////
            //
            // count unsubscribes
            //
            ///////////////////////////////////////////////////////////////////

            ET_UnsubEvent unsubscribe = new ET_UnsubEvent();
            unsubscribe.GetSinceLastBatch = false;
            unsubscribe.AuthStub = client;
            unsubscribe.SearchFilter = filter;
            unsubscribe.Props = properties;

            results = unsubscribe.Get();

            foreach (ET_UnsubEvent item in results.Results)
            {
                if (!dictionary.ContainsKey(item.SendID))
                {
                    dictionary[item.SendID] = new ProviderMetrics();
                    dictionary[item.SendID].Name = GetEmailName(client, item.SendID);
                }

                dictionary[item.SendID].Unsubscribes++;
            }

            return dictionary.Values;
        }