ddetering
asked on
replacing several links in an (html) string
Hi!
I am trying to create tracking capability for bulk email that my application sends out to subscribers. The emails are event invitations with links mostly leading to the organizers' websites. There are txt and html invites, and I would like to track who of our subscribers clicked on which link. I know how to do this in general:
Replace all outbound links with lokal links. Global.asax will recognize a pattern in those local links, look up the real link from the database for a redirect and also write some tracking info to the database.
Unfortunately, I am not even past the first step, which I tried to accomplish this way:
Dim colLinks As ArrayList = New ArrayList
'colLinks is supposed to hold all the different links (case insensitive)
'after the link replacement, colLinks' links will then be written to the database
'along with their array index
'and the id of this particular promotion (which is available here as Request.QueryString("Promo tion")
'inviteTxt is the text invitation
'inviteHtml is the html invitation
Dim linkStart As String = "http://"
For Each linkStart In inviteTxt
Dim link As String = (inviteTxt.Substring(invit eTxt.Index Of(linkSta rt), inviteTxt.IndexOf(" ") - 1))
If Not link.IndexOf("MySite.com/L ink/") > -1 Then
colLinks.Add(link)
'running the replacement of a found link in the txt invite first:
inviteTxt.Replace(link.ToL ower, "http://www.MySite.com/Link/" & encryptQueryString(Request .QueryStri ng("Promot ion")) & "/" & colLinks.IndexOf(link) & "/Link123.aspx")
'also running the replacement of a found link in the html invite, too:
inviteHtml.Replace("href=" "" & link.ToLower, "href=""http://www.MySite.com/Link/" & encryptQueryString(Request .QueryStri ng("Promot ion")) & "/" & colLinks.IndexOf(link) & "/Link123.aspx")
End If
Next
'running the replacement on all links found in the html invite only:
linkStart = "href="""
For Each linkStart In inviteHtml
Dim link As String = (inviteHtml.Substring(invi teHtml.Ind exOf(linkS tart) + 5, inviteHtml.IndexOf(""">") - 1))
If Not link.IndexOf("MySite.com/L ink/") > -1 Then
colLinks.Add(link)
inviteHtml.Replace(link.To Lower, "http://www.MySite.com/Link/" & encryptQueryString(Request .QueryStri ng("Promot ion")) & "/" & colLinks.IndexOf(link) & "/Link123.aspx")
End If
Next
The problem is that nothing happens - no error, no replacing of links. I guess I am just not good enough with looping through a string. Right?
I am trying to create tracking capability for bulk email that my application sends out to subscribers. The emails are event invitations with links mostly leading to the organizers' websites. There are txt and html invites, and I would like to track who of our subscribers clicked on which link. I know how to do this in general:
Replace all outbound links with lokal links. Global.asax will recognize a pattern in those local links, look up the real link from the database for a redirect and also write some tracking info to the database.
Unfortunately, I am not even past the first step, which I tried to accomplish this way:
Dim colLinks As ArrayList = New ArrayList
'colLinks is supposed to hold all the different links (case insensitive)
'after the link replacement, colLinks' links will then be written to the database
'along with their array index
'and the id of this particular promotion (which is available here as Request.QueryString("Promo
'inviteTxt is the text invitation
'inviteHtml is the html invitation
Dim linkStart As String = "http://"
For Each linkStart In inviteTxt
Dim link As String = (inviteTxt.Substring(invit
If Not link.IndexOf("MySite.com/L
colLinks.Add(link)
'running the replacement of a found link in the txt invite first:
inviteTxt.Replace(link.ToL
'also running the replacement of a found link in the html invite, too:
inviteHtml.Replace("href="
End If
Next
'running the replacement on all links found in the html invite only:
linkStart = "href="""
For Each linkStart In inviteHtml
Dim link As String = (inviteHtml.Substring(invi
If Not link.IndexOf("MySite.com/L
colLinks.Add(link)
inviteHtml.Replace(link.To
End If
Next
The problem is that nothing happens - no error, no replacing of links. I guess I am just not good enough with looping through a string. Right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
James! It seems like you were right! I've got it to work! It must have been because of me failing to assign the worked-on string to itself again...
The reason I want to use query strings as little as possible is that some email clients choke on it and for some tracking methods it exposes you to the risk of having them stripped by some ISPs. Yes, you are right: We can't see whether you are opening our emails if you get them as txt, but with my method it is very hard for you to respond (click on a link) without us noticing it. It's not all bad, though, because we use that information to provide you with a better service (and to ensure that we keep making enough money to provide that service at all!).
Cheers,
Dietmar
The reason I want to use query strings as little as possible is that some email clients choke on it and for some tracking methods it exposes you to the risk of having them stripped by some ISPs. Yes, you are right: We can't see whether you are opening our emails if you get them as txt, but with my method it is very hard for you to respond (click on a link) without us noticing it. It's not all bad, though, because we use that information to provide you with a better service (and to ensure that we keep making enough money to provide that service at all!).
Cheers,
Dietmar
Glad i could help
ASKER
Dim stringIndex As Integer
Dim linkStart As String = "http://"
Dim link As String
For stringIndex = 0 To inviteTxt.Length - 8
If inviteTxt.Substring(string
link = (inviteTxt.Substring(strin
If Not link.IndexOf("MySite.com/L
colLinks.Add(link)
inviteTxt.Replace(link.ToL
inviteHtml.Replace("href="
End If
End If
Next
But again, nothing happens. No error, but no change to the links either. Also, looping characterwise through a long string with thousands of characters seems very inefficient to me, even though it will happen only a few times per hour. Any improvement ideas will be appreciated.