Puneeth Kumar
Puneeth Kumar

Reputation: 192

How to change normal urls to SparkPost Custom URL in SparkPost API using PHP?

Im trying to send a email template along with a URL whose click count should be tracked using SparkPost APIs?

Example: if I give www.google.com its has to change to

http://go.sparkpostmail1.com/f/a/EgvUoS2LdGPzMx-AURKwZA~~/AABUGAA~/RgRZK0BSP0EIAGukLuGW3OxXA3NwY1gEAAAAAFkGc2hhcmVkQgoAAVK7SFdpNVEbUhFuaWNvbGFzQGR1cmFuZC5jaAlRBAAAAABEUWh0dHBzOi8vZGlzaGx5Lm1lbnUvZC9XYXNoaW5ndG9uL1JlZ2VudF9UaGFpL0Jhc2lsX0phZS81NjBmMzk5MmQ0YWUxNTAzMDBmZWZmMGIiLEcCe30.

POST /api/v1/transmissions?num_rcpt_errors=3

 {
  "options": {
    "start_time": "now",
    "open_tracking": true,
    "click_tracking": true,
    "transactional": false,
    "sandbox": false,
    "ip_pool": "sp_shared",
    "inline_css": false
  },
  "description": "Christmas Campaign Email",
  "campaign_id": "christmas_campaign",
  "metadata": {
    "user_type": "students",
    "education_level": "college"
  },
  "substitution_data": {
    "sender": "Big Store Team",
    "holiday_name": "Christmas"
  },
  "recipients": [
    {
      "address": {
        "email": "[email protected]",
        "name": "Wilma Flintstone"
      },
      "tags": [
        "greeting",
        "prehistoric",
        "fred",
        "flintstone"
      ],
      "metadata": {
        "age": "24",
        "place": "Bedrock"
      },
      "substitution_data": {
        "customer_type": "Platinum",
        "year": "Freshman"
      }
    }
  ],
  "content": {
    "from": {
      "name": "Fred Flintstone",
      "email": "[email protected]"
    },
    "subject": "Big Christmas savings!",
    "reply_to": "Christmas Sales <[email protected]>",
    "headers": {
      "X-Customer-Campaign-ID": "christmas_campaign"
    },
    "text": "Hi  \nSave big this Christmas in your area ! \nClick http://www.example.com and get huge discount\n Hurry, this offer is only to \n ",
    "html": "<p>Hi  \nSave big this Christmas in your area ! \nClick http://www.example.com and get huge discount\n</p><p>Hurry, this offer is only to \n</p><p></p>"
  }
}

Upvotes: 1

Views: 661

Answers (1)

Ewan Dennis
Ewan Dennis

Reputation: 396

To enable "click tracking", set options.click_tracking=true field in your request. You have already done this but it looks like your links in the content.html are not HTML anchors (<a> tags) but just plain text links.

SparkPost will only track HTML anchors so I suggest changing this:

http://www.example.com

to this:

<a href="http://www.example.com">www.example.com</a>

Upvotes: 0

Related Questions