Rewrite URL:s and add tracking pixels to track user engagement.
This HSL module is compatible with the payload format used by the extended version of the HTTP submission API.
Follow the instructions in our manual to add our package repository and then run the below command.
apt-get install halon-extras-tracking
yum install halon-extras-tracking
These functions needs to be imported from the extras://tracking module path.
Enables user engagement tracking for the recipient.
Params
- mail
MailMessage- The mail object Required - recipient
string- The recipient Required - tracking
array- The tracking settings Required
The following properties are available in the tracking array.
- url
string- The base url that should be used for the rewritten links and tracking pixels Required - secret
array- The secret settings Required - click
boolean- If click tracking should be enabled - open
boolean- If open tracking should be enabled - unsubscribe
boolean- If one-click list unsubscribe should be enabled - additional
array- Additional data to store in the link
The following properties are available in the secret array.
- id
number- The ID of the secret that should be used to generate the hash of the tracking payload. This must be an integer between1and254Required - key
string- The key for the secret that should be used to generate the hash of the tracking payload Required
import { enable_tracking } from "extras://tracking";
$tracking = [
"click" => true,
"open" => true,
"unsubscribe" => false,
"url" => "http://example.com",
"secret" => [
"id" => 1,
"key" => "badsecret"
],
"additional" => ["foo" => "bar"]
];
// Queue message for all recipients
$id = $mail->snapshot();
foreach ($recipients as $recipient) {
enable_tracking($mail, $recipient["recipient"], $tracking);
$mail->queue($sender, $recipient["address"], $recipient["transportid"]);
$mail->restore($id);
}
Warning
This requires multipart processing to be enabled on your message flow in smtpd-app.yaml - see here.
Links can be excluded from tracking by adding the tracking="off" attribute to the anchor tag.
<a tracking="off" href="https://halon.io">Halon Website</a>