Sendgrid: How to add a dynamic link to an email template?

Viewed 7214

I am trying to have a link in my email template that would sort of look like this:

<a href={{url}}>click here</>

The above link has been added in de "designer" by adding a "custom" link. The value for this like I enterd as {{url}}.

I pass an url value in the dynamic_template_data, like so:

const msg = {
  to: savedAdmin.email,
  from: process.env.EMAIL_ADDRESS,
  templateId: process.env.SENDGRID_NEW_ADMIN_TEMPLATE_ID,
  personalizations: [
    {
      to: [{email: savedAdmin.email}],
      dynamic_template_data: {
        name: savedAdmin.first_name,
        url: process.env.CMS_URL,
        email: savedAdmin.email,
        password: randomPassword,
      },
    },
  ],
};

However, the url gets rendered like this when I receive the mail in my inbox:

http://url9905.myweb.shop/ls/click?upn=BMmHdsRoNrbb0-2FMI-2BBVvCjpDiCceHLG5U2u5OCf29QV6iCtfuvZYId1FE95cTz9uyMY31z9fQ7iR-2BPgq-2FkquvxdAPC0oMKiLa3DRglYUSVP-2FRmYbDQ-2BdFGnczXk75K3Ym8rSodsrAy-2BfNDJwqA7RDeemPFjepjRsUdci9CA6Y0-....

How do I get this to work?

2 Answers

Sendgrid is replacing your link with a intermediary redirect for click tracking. This user experienced the same issue. From the Sendgrid dashboard, go to Settings->Tracking and click the edit icon on the right for Click Tracking, and disable the feature.

looks like the cause of this issue is due to not including the http/s prefix to your link. Please change your dynamic variable from "cms.mywebshop.com" to "http://cms.mywebshop.com" or "https://cms.mywebshop.com". Pretty sure this should resolve your issue. Please let me know.

I was able to test not having the http/s prefix on one of my href's and although the tag did not appear as show as plain text, it did fail to forward. It's possible that the folks from Sendgrid made it so the link is shown as plain text for troubleshooting purposes.

Related