使用jQuery和Google跟踪代码管理器通过SendGrid发送交易电子邮件

问题描述 投票:0回答:1

当某些事件被触发时,我正在尝试使用google标记管理器自定义html标记发送电子邮件。

这是代码(在需要时省略XXXXX)

<script>
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "https://api.sendgrid.com/v3/mail/send",
      "method": "POST",
      "headers": {
        "authorization": "Bearer XXXXXXXXXXXXX",
        "content-type": "application/json"
      },
      "processData": false,
      "data": "{\"personalizations\":[{\"to\":[{\"email\":\"XXXXXXXXXX\",\"name\":\"John Doe\"}],\"dynamic_template_data\":{\"verb\":\"yes\",\"adjective\":\"test\",\"noun\":\"\",\"currentDayofWeek\":\"\"},\"subject\":\"Hello, World!\"}],\"from\":{\"email\":\"XXXXXXXXXXXXXXX\",\"name\":\"John Doe\"},\"reply_to\":{\"email\":\"XXXXXXXXXXXXXXX\",\"name\":\"John Doe\"},\"template_id\":\"XXXXXXXXXXXXXXX"}"
    }

    jQuery.ajax(settings).done(function (response) {
      console.log(response);
    });
    </script>

现在,使用内置的发送网格“试用”功能时,将运行此块(减去脚本标签)。为什么这在GTM上不起作用?

sendgrid sendgrid-api-v3
1个回答
0
投票

类似这样的代码的声音可能会在jQuery准备就绪之前被添加并运行。尝试对代码进行以下更新:

<script>
  jQuery(function() {
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "https://api.sendgrid.com/v3/mail/send",
      "method": "POST",
      "headers": {
        "authorization": "Bearer XXXXXXXXXXXXX",
        "content-type": "application/json"
      },
      "processData": false,
      "data": "{\"personalizations\":[{\"to\":[{\"email\":\"XXXXXXXXXX\",\"name\":\"John Doe\"}],\"dynamic_template_data\":{\"verb\":\"yes\",\"adjective\":\"test\",\"noun\":\"\",\"currentDayofWeek\":\"\"},\"subject\":\"Hello, World!\"}],\"from\":{\"email\":\"XXXXXXXXXXXXXXX\",\"name\":\"John Doe\"},\"reply_to\":{\"email\":\"XXXXXXXXXXXXXXX\",\"name\":\"John Doe\"},\"template_id\":\"XXXXXXXXXXXXXXX"}"
    }

    jQuery.ajax(settings).done(function (response) {
      console.log("SendGrid Response:", response);
    });
  });
</script>

尝试一下,看看是否在控制台中看到标有“ SendGrid Response:”的任何内容。这一定会让我们知道该脚本是否正在运行。

© www.soinside.com 2019 - 2024. All rights reserved.