Selectively track Marketo links and opens based on lead opt-in (think GDPR, o’course)

GDPR and related regulations call for some fancy footwork with activity tracking.

Leads may be members of the same program, set to receive the same email… but many have opted-out of tracking, while the rest agreed to be tracked for the greater good.

So you need the same email to go out, but some get the tracked version of links (bounced off your branding domain) while others get the raw links (straight to the URL). Same for the <img> that tracks opens: some get the pixel, others don't.

The solution, as for so many things, is Velocity.

If canBeTracked is your Boolean lead field, first convert it to a number:

#set( $link = "https://info.example.com/somepage.html" )
#set( $canBeTracked = $convert.toNumber("0${lead.canBeTracked}") )

Then you can use this VTL logic to selectively track links:

#set( $trackingClass = "{0,choice,0#mktNoTrack|1#}" )
<a class="${display.message($trackingClass, $canBeTracked)}" 
   href="http://www.example.com/page.html">Le Click, C'est Chic</a>

That'll output a tracked link for those that opted in, an untracked link for everyone else.

To selectively track opens, first disable open tracking in Email Settings:

Then manually include the open-tracking pixel in the template:

#set( $trackingLink = "http://click.example.com/trk?t=1&mid=${mktmail.QpMarketoId}" )
<img src="${display.message("{0,choice,0#|1#${trackingLink}}", $canBeTracked)}">

What's that $display.message() thing?

Explained the code concepts over here to keep this post short.