voidlabs / mosaico

Mosaico - Responsive Email Template Editor
https://mosaico.io
GNU General Public License v3.0
1.71k stars 504 forks source link

Add tracker params to all URL in template #502

Closed rimkat closed 5 years ago

rimkat commented 5 years ago

Hi,

Please help me :(

I would like to add several tracker params to all href in a template. When trying the proposed method (concatenation) I have this error parser.js:3 TODO ERROR Property lookup exception Found an unexpected path termination url for model HeaderAndText for titleLink.url HeaderAndText titleLink.url HeaderAndText titleLink.url Model ensure path failed undefined name -ko-attr-href value @[titleLink.url]@[trackingOrigin] default https://www.google.com/ element Exception while parsing the template Exception parsing expression @[titleLink.url]@[trackingOrigin] Found an unexpected path termination url for model HeaderAndText for titleLink.url stylesheet.js:2 Uncaught Exception parsing expression @[titleLink.url]@[trackingOrigin] Found an unexpected path termination url for model HeaderAndText for titleLink.url

My goal is to build a link like https://url/#{(trackingOrigin)}|trackingSource&g.lu= I try to concatenate by doing "-ko-attr-href:@[titleLink.url]@[_root_.trackingOrigin]@[_root_.trackingSource]" I have defined the elements in "@support -ko-blockdefs" like that : template { label: Template; properties: trackingOrigin=XXXXXX trackingSource=000000; } titleLink {label: Title link;extend: link;} trackingOrigin {label: Tracking Origin; extend:text;} trackingSource {label: Tracking Source; extend:text;}

Can you tell me if the method is good or not?

Thx

bago commented 5 years ago

The error say it doesn't like "@[titleLink.url]@[trackingOrigin]" while you say you used "@[titleLink.url]@[root.trackingOrigin]": first of all double check it.

We think url manipulation is something belonging to the sending environment and not a template builder, so I won't say the method is "good". That said you can use the template language features the way you like :-)

rimkat commented 5 years ago

Hi bago,

Thanks for your answer.

So much for me I posted the wrong test. At first I tried to modify a variable declared in the block concerned, once the conclusive tests I would have liked to declare it in the template and avoid repeating it I do not know if it's clear enough. Method 1: For example to get this "https:// url/tracking=ORIGINSOURCE" I do <h1> <a href="https://url/tracking=" target="_ blank" style ="-ko-attr-href: @['https://url/tracking =' + _root_.trackingOrigin + _root_.trackingSource]"> this is header </a></ h1> it works.

Method 2: I would have liked to do the same thing using this way style ="-ko-attr-href: @[titleLink.url]@[trackingOrigin]@[trackingSource]"

How can I also compose an URL of the type https://url/#{[trackingOrigin]}|trackingSource&g.lu= using the first method ? -ko-attr-href: @['https://url/#{[' + _root_.trackingOrigin + ']}|' + _root_.trackingSource + '&g.lu=']

I know it's not the best way even if it's like you say 'good' but I did not find any other possibility.

Thank you ;)

bago commented 5 years ago

I don't follow you.

In "Method 2" you say you'd like to apply Method 1 to "@[titleLink.url]@[trackingOrigin]@[trackingSource]", and it should be simply "@[titleLink.url+trackingOrigin+trackingSource]" but then you start using weird sequences like "#{[": what are they?

The right way is Method 1, but maybe there are limits in the characters allowed in an expression so I don't know if it will let you use "#{[|" in the expression.

rimkat commented 5 years ago

The method 1 is indeed the one that works and that is the most adapted to my need. I tried method 2 for "simple" links that do not contain special characters, just a try. And it's where I have a problem, some of my url contain specific characters such as "# {[|" and I think it's going to make mistakes.

rimkat commented 5 years ago

I would have liked to concatenate with variables sometimes separated by special characters. Complete a link like https://url/#{[trackingOrigin]}|trackingSource&g.lu=otherTracking...