public void EnableGoogleAnalytics()
        {
            var header = new Header();
            var sendgrid = new SendGrid(header);

            var source = "SomeDomain.com";
            var medium = "Email";
            var term = "keyword1, keyword2, keyword3";
            var content = "PG, PG13";
            var campaign = "my_campaign";

            sendgrid.EnableGoogleAnalytics(source, medium, term, content, campaign);

            var jsonSource = "\"utm_source\" : \"SomeDomain.com\"";
            var jsonMedium = "\"utm_medium\" : \"" + medium + "\"";
            var jsonTerm = "\"utm_term\" : \"" + term + "\"";
            var jsonContent = "\"utm_content\" : \"" + content + "\"";
            var jsonCampaign = "\"utm_campaign\" : \"" + campaign + "\"";

            var json = header.JsonString();
            Assert.AreEqual("{\"filters\" : {\"ganalytics\" : {\"settings\" : {\"enable\" : \"1\"," +
                            jsonSource + "," + jsonMedium + "," + jsonTerm + "," + jsonContent + "," + jsonCampaign + "}}}}",
                json);
        }
Beispiel #2
0
        /// <summary>
        ///     The Footer App will insert a custom footer at the bottom of the text and HTML bodies.
        ///     http://docs.sendgrid.com/documentation/apps/google-analytics/
        /// </summary>
        public void EnableGoogleAnalytics()
        {
            //create a new message object
            var message = new SendGrid();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
            message.Html = "<p style='color:red';>Hello World</p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";
            message.Html += "Checkout my page at <a href=\"http://microsoft.com\">Microsoft</a>";

            message.Text = "Hello World plain text";

            //set the message subject
            message.Subject = "Hello World Footer Test";

            //create an instance of the Web transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable Google Analytics
            message.EnableGoogleAnalytics("SendGridTest", "EMAIL", "Sendgrid", "ad-one", "My SG Campaign");

            //send the mail
            transportInstance.Deliver(message);
        }