public void Test_EnablingGoogleAnalytics() { var mail = BasicMailBuilder .EnableGoogleAnalytics("source", "medium", "term", content: "content", campaign: "campaign") .Build(); var message = new SendGridMessage(); message.EnableGoogleAnalytics("source", "medium", "term", content: "content", campaign: "campaign"); Assert.IsFalse(string.IsNullOrEmpty(message.Header.JsonString())); Assert.AreEqual(message.Header.JsonString(), mail.Header.JsonString()); }
public MailBuilder EnableGoogleAnalytics(string source, string medium, string term, string content = null, string campaign = null) { sendgrid.EnableGoogleAnalytics(source, medium, term, content, campaign); return(this); }
/// <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 SendGridMessage(); //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.DeliverAsync(message); }
public void EnableGoogleAnalytics() { var header = new Header(); var sendgrid = new SendGridMessage(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); }