Not so long ago, I faced an issue while wanted to test a colleague idea: how can we test on which links user are more willing to click.
TL;DR
If my article is too long, these are the steps:
- Define the scope
- Extract or get the HTML content
- Split your group (in three in my case)
- Write a script
- Run the script
- Push your changes
And this is the script I use for the curious: The Script
The process
So the first step was to define the scope of your changes. In my case it was for an experiment, we wanted to test the impact of style on links from blogs posts.
I'll let you ran some test and opportunity sizing to define how many articles and for how long you should run the test [tip: it will depend on how many sessions / user interaction you have]. For this article, let's say 500 blog posts for a two weeks period of time.
Out of these 500 articles, I extract 100 for the first variant, 100 for the second variant and 300 for the control group. [Remember that numbers may change based of your data and your goal!]
Why creating a script: because of sample for both variants was over a hundred blog posts each. No way we would have done this manually.
The script
For this purpose, I used Python that was the most adapted to the situation & for the user to easily reproduce. But if you are more “fluent” in R, PHP, Ruby, JS, you might be able to adapt it 😁.
import pandas as pd from bs4 import BeautifulSoup # Function to add bold red style to links def bold_red(body_html): soup = BeautifulSoup(body_html, 'html.parser') for a in soup.find_all('a', href=True): a['style'] = "color: #880808; font-weight: bold;" return str(soup) # Function to add italic underline black style to links def italic_underline_black(body_html): soup = BeautifulSoup(body_html, 'html.parser') for a in soup.find_all('a', href=True): a['style'] = "color: #000000; font-style: italic; text-decoration: underline;" return str(soup) variant1['new_body_html'] = variant1['body_html'].apply(bold_red) variant2['new_body_html'] = variant2['body_html'].apply(italic_underline_black)
Let me explain this script a little! First, I am creating two functions that I could apply to the two selected group. These two functions leverage BeautifulSoup
to achieve the search and replace. And finally, I am using apply to make changes in bulk.
And then?
This was not the end of the script and< the automation. If you know me a bit, I like to automate and simplify process. The other part of the script (that I am not able to share) aimed to ship these changes in bulk.
Yes, once the HTML is modified, the next logical step is to ship those changes and run the experiment. I am sure if you are using a CMS you can easily achieve that.
If you want some result, ping me on X (formerly Twitter), LinkedIn or Bluesky. And if many of you are interested in this test, I'll create a recap article.