Lightweight A/B testing using Velocity | Community
Skip to main content
Jon_Wright
New Participant
March 2, 2021
Solved

Lightweight A/B testing using Velocity

  • March 2, 2021
  • 1 reply
  • 3825 views

Hi @sanfordwhiteman  I've been looking to use this

https://blog.teknkl.com/lightweight-a-b-testing-in-velocity/

 

but also with different (tracked) links. I'm aware of the multiple tracked links issue but I though renaming the variable would work e.g.

 

 

#set( $random = $math.random(0,3) ) #set( $member_cta = { 0 : {"text": "Text 0", "link_text": "Link text 0", "url": "www.example.com?l=0" }, 1 : {"text": "Text 1", "link_text": "Link text 1", "url": "www.example.com?l=1" }, 2 : {"text": "Text 2", "link_text": "Link text 2", "url": "www.example.com?l=2" } }) #set($url_new = $member_cta[$random].url) ${member_cta[$random].text} <a href="https://${url_new}" style="color: #ffffff;"> ${member_cta[$random].link_text}</a> ${url_new} </div>

 

 

And indeed it was, but turns out it was only working 'randomly'. I only want to output 1 link, what am I doing wrong here?

Thanks
Jon

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jon_Wright
It's just not possible because of the way the UberSpector works.

Thanks for confirming. Saves me tearing any more hair out.

1 reply

SanfordWhiteman
New Participant
March 2, 2021

Hi Jon,

 

I tried responding to your comment on my blog, but by then it was deleted!

 

The problem is that your options HashMaps are still ultimately properties of the same $member_cta object.  (Well, if we looked at them in Java terms, they're not owned by the $member_cta in any way, but from the perspective of the Velocity UberSpector, the fact that they're referenced as properties of the HashMap makes them seem like "children" of the HashMap.)

 

You would have to create entirely different top-level objects.

Jon_Wright
New Participant
March 2, 2021

Thanks @sanfordwhiteman . I did post there but couldn't get the script to display in the comments so thought better to post over here instead.

 

So I've tried this (thinking I was creating a new object) but still no joy. 

#set( $random = $math.random(0,3) ) #set( $member_cta = { 0 : {"text": "Text 0", "link_text": "Link text 0", "url": "www.tmforum.org/toolkits-overview/?l=0", "campaign": "member-footer" }, 1 : {"text": "Text 1", "link_text": "Link text 1", "url": "www.tmforum.org/toolkits-overview/?l=1", "campaign": "member-footer" }, 2 : {"text": "Text 2", "link_text": "Link text 2", "url": "www.tmforum.org/toolkits-overview/?l=2", "campaign": "member-footer" } }) #set($cta = $member_cta[$random]) #set($new = {}) #set($void = $new.put("u", $cta) ) #set($new_url = $new["u"].url) <div><b>${new["u"].text}</b> <a href="https://${new_url}" style="color: #ffffff;"> ${new["u"].link_text}</a> $new </div>

 

SanfordWhiteman
New Participant
March 2, 2021

Markdown works on my blog, FYI.

 

This still isn't a new object because it's just shuttling the object reference around.