, , , , ,

Hello world,
Today I would like to show you why variable text in a streamdocument disappears after an ampersand and what you can do to prevent that. Therefore we need to take a closer look at url encoding and the way that DirectSmile Cross Media changes links automatically.

I created a purl and a document. The document contains a textvariable, the first name. Save all.

I placed the document on a purl and text with an ampersand is displayed correctly.

Sometimes you don’t want to show a preview of the PDF on the purl, you simply want a link that opens the document as PDF in the browser directly. Therefore you can use the streamdocument url, even for the VDP Online documents. We have been using the streamdocument url for uploaded VDP Studio documents a long time and if you already know it, you will see that it is very similar to the older method.

I placed a link item, switched it to External and inserted the streamdocument url:

As you can see in the picture above, the streamdocument method is almost like the older one. In addition to the document name, you need to place the campaign name. To address the variables in the document, you need to add the text xtdi_db_ before each variable’s name.

But if you click the link, all text after the ampersand disappears:


Why? Because the ampersand is not recognized as text. This information is sent to the streamdocument:

Tick, Trick & Track

The ampersand is recognized as part of the url, rather like a connecting element (what is not a surprise, because we use it to connect variables in the streamdocument url all the time). It needs to be url encoded.

Solution – step 1
In order to make text work in a url, you can use the “url encode” function: create a new textvariable (green plus icon in the variables tab), select function, select Url Encode and select the database column. Update the variable’s name in the streamdocument url to the new textvariable’s name, here: EncFirstname

You can already see the encoded text in the small preview below the variable’s name: Tick%2c+Trick+%26+Track

%2c is the comma
%26 is the ampersand
+ is the space

If that would be used in the streamdocument url, it would look fine, since the text Tick%2c+Trick+%26+Track would be send to the streamdocument an the decoded result on the document’s page would be Tick, Trick & Track. You can test it if you click this link:


That works fine.

But WHY is it still not working if you click the Link on the purl?

Because the link on our purl does not look like this:

It actually looks like this:

To understand that, we need to find out…

… what happens to links in Cross Media?
At first, let’s have a look at the changes that are made to all links (regardless streamdocument or not). Therefore I placed a very simple link to my blog:

If you preview the purl in the browser and hover over the link, you can see the link text. It is much longer than the that link I created originally:

Why does it look like this?
Because Cross Media needs more information to track the link properly, not only where it is going to, but also where it comes from. The original link is now part of what I call the ‘trackinglink’. The important information for tracking are e.g. the page name and a unique tracking id. Last but not least it also contains the original link at the end. If you click the trackinglink, you will be redirected to the original link and the click can be tracked. That is why you can see the results later in the campaign dashboard:

Cross Media encodes the original link automatically to:

%3a is the colon
%2f is the slash

If you click the trackinglink, the original link will be decoded during the redirection and you will get to: https://lbatree.wordpress.com

That means, if you place a link on a purl:
1. Cross Media creates the trackinglink and encodes the original link
2. If the trackinglink is clicked, it redirects to the decoded original link

The same happens with the streamdocument link. You can see it, if you hover over the Click Me on the purl. Unfortunately that link is too long to see it in the browser.

With a right mouse click on the link Click here you can click Copy link address:

If you paste it into a text editor, you can see the link that Cross Media created. Pay attention to the original link inside the tracking link. It has been url encoded, so it looks like this:

The ampersand is encoded correctly:  Tick%2c+Trick+%26+Track
But if you click the trackinglink and Cross Media redirects you to the original link, it will be decoded automatically to… exactly…

Tick, Trick & Track

And again, if Tick, Trick & Track is send to the streamdocument, the ampersand is already decoded and would not be displayed as text in the document. That means, that encoding it once is not enough. We need double encoding!

Solution – step 2
To double encode the variable, open the properties of EncFirstname and click on [[Firstname]]

Click function:

Select the function Url Encode:

Click ”Value”, click the database icon and select the Firstname:

As you can see in the small preview already, the text variable is encoded twice:

%25 is the percentage sign
%2b is the plus sign

If you click the trackinglink, the part

will be decoded to:

and finally, this is is the correct information that the streamdocument needs, because now the ampersand is still encoded with %26 and in the document it can be encoded and displayed as what it is, an ampersand sign.

Here you can test the links, have fun :-)