【问题标题】:SparkPost - not receiving Click EventsSparkPost - 未收到点击事件
【发布时间】:2016-08-29 20:26:23
【问题描述】:

所以,我有一个 http 端点,用于从 SparkPost 接收不同类型的事件(例如 Delivery、Bounce、Complaint、Open Track,...)。一切正常,但我没有收到任何关于 Click 事件的帖子。到目前为止,这是我尝试过的:

 private void sendEmail(String from, String[] recipients) throws SparkPostException {
    TransmissionWithRecipientArray transmission = new TransmissionWithRecipientArray();

    ArrayList<String> tags = new ArrayList<String>();
    tags.add("tag #1");
    tags.add("tag #2");
    // Populate Recipients
    List<RecipientAttributes> recipientArray = new ArrayList<RecipientAttributes>();
    for (String recipient : recipients) {
        RecipientAttributes recipientAttribs = new RecipientAttributes();
        recipientAttribs.setAddress(new AddressAttributes(recipient));
        recipientAttribs.setTags(tags);
        recipientArray.add(recipientAttribs);
    }
    transmission.setRecipientArray(recipientArray);

    // Populate Substitution Data
    Map<String, Object> substitutionData = new HashMap<String, Object>();
    substitutionData.put("link", "http://www.google.com?utm_campaign=test_campaign");


    OptionsAttributes optionsAttributes = new OptionsAttributes();
    optionsAttributes.setClickTracking(true); // THIS DOESN'T SEEM TO MAKE A DIFFERENCE
    optionsAttributes.setOpenTracking(true);


    transmission.setSubstitutionData(substitutionData);
    transmission.setOptions(optionsAttributes);
    transmission.setCampaignId("test_campaign");

    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("user_type", "test");
    transmission.setMetadata(metadata);
    transmission.setReturnPath("example@some-mail.com");
    // Populate Email Body
    TemplateContentAttributes contentAttributes = new TemplateContentAttributes();
    contentAttributes.setFrom(new AddressAttributes(from));
    contentAttributes.setSubject("Your subject content here.");
    contentAttributes.setText("Your Text content here.");

    contentAttributes.setHtml("<p>Your <b>HTML</b> content here. {{ link }}</p>");

    transmission.setContentAttributes(contentAttributes);

    transmission.setContentAttributes(contentAttributes);

    // Send the Email
    RestConnection connection = new RestConnection(this.client, getEndPoint());
    Response response = ResourceTransmissions.create(connection, 0, transmission);

    System.out.println("Transmission Response: " + response);
}

【问题讨论】:

  • 嘿@peech :) 您是否已将其中一封电子邮件发送给自己?我认为您的链接正在转义,因为您使用的是双花括号。尝试三重花括号 {{{ link }}} 以防止 html 转义。
  • 这也不起作用:/ 如果我将&lt;a href="http://www.google.com"&gt;Google&lt;/a&gt; 直接放入contentAttributes.setHtml(),我会收到一个点击事件。从substitutionData放入时,点击事件未到达。
  • 在您收到的电子邮件中,域是否指向 SparkPost 点击跟踪服务器,即 spgo.io,还是仍然是 google.com?
  • 它仍然是 google.com
  • 这实际上是一个操作顺序。例如,当您个性化整个链接时,我们的模板引擎需要能够查看 url 方案,以确保它不会尝试链接包装 mailto: 链接。我会在答案中提供更多细节。

标签: java sparkpost


【解决方案1】:

为了让 SparkPost 模板引擎仅个性化 http(s)? 网址,而不是包装 mailto:a@b.com 之类的内容,方案(http://https://)需要在模板中,而不是在替代数据。这是一个例子:

模板: This is a link to <a href="http://{{{myurl}}}">somewhere awesome</a>!

替换数据: substitutionData.put("myurl", "www.google.com?utm_campaign=test_campaign");

这里实际上有三个变化——第二个变化是使用三重大括号{{{ 而不是{{ 双大括号,以避免 html 转义替换变量的内容。第三个是将 url 放在锚标签中,因为 SparkPost 不会包装裸链接。

【讨论】:

  • 谢谢,这按预期工作。不敢相信我自己没想到...
猜你喜欢
  • 2015-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-11
  • 2019-08-31
  • 1970-01-01
相关资源
最近更新 更多