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.
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.
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.
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
%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.
To understand that, we need to find out…
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 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!
%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 :-)