?
Solved

replacing several links in an (html) string

Posted on 2004-10-20
4
Medium Priority
?
234 Views
Last Modified: 2010-04-23
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("Promotion")
'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(inviteTxt.IndexOf(linkStart), inviteTxt.IndexOf(" ") - 1))
       If Not link.IndexOf("MySite.com/Link/") > -1 Then
           colLinks.Add(link)

'running the replacement of a found link in the txt invite first:
           inviteTxt.Replace(link.ToLower, "http://www.MySite.com/Link/" & encryptQueryString(Request.QueryString("Promotion")) & "/" & 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.QueryString("Promotion")) & "/" & 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(inviteHtml.IndexOf(linkStart) + 5, inviteHtml.IndexOf(""">") - 1))
       If Not link.IndexOf("MySite.com/Link/") > -1 Then
           colLinks.Add(link)
           inviteHtml.Replace(link.ToLower, "http://www.MySite.com/Link/" & encryptQueryString(Request.QueryString("Promotion")) & "/" & 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?
0
Comment
Question by:ddetering
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:ddetering
ID: 12366290
Been trying it with a new loop (I think the loop part is working now):

Dim stringIndex As Integer
Dim linkStart As String = "http://"
Dim link As String
For stringIndex = 0 To inviteTxt.Length - 8
    If inviteTxt.Substring(stringIndex, 7) = linkStart Then
        link = (inviteTxt.Substring(stringIndex, inviteTxt.Remove(0, stringIndex).IndexOf(" ")))

        If Not link.IndexOf("MySite.com/Link/") > -1 Then
            colLinks.Add(link)

            inviteTxt.Replace(link.ToLower, "http://www.MySite.com/Link/" & encryptQueryString(Request.QueryString("Promotion")) & "/" & colLinks.IndexOf(link) & "/Link123.aspx")

            inviteHtml.Replace("href=""" & link.ToLower, "href=""http://www.MySite.com/Link/" & encryptQueryString(Request.QueryString("Promotion")) & "/" & colLinks.IndexOf(link) & "/Link123.aspx")
        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.
0
 
LVL 10

Accepted Solution

by:
james-ct16 earned 1120 total points
ID: 12369343
Hi

I might be missing something here but surely the following is far simpler

when registering a new subscriber they probably have an id of some description, so simply generate a key based on that id.
so then on your email send out a href to eg index.aspx?sub=[key]

on the index.aspx page or whatever entry page you read in the sub querystring and then tick it off as a subscriber who visited. so simply read this in as you execute the on page load event

as a note you can apply this same technic to the emails you send out, if you include html elements eg an aspx page sending jpegs can except query string and you would then detect the email being opened. hence why i have html mail turned off

hope that is of some help, it is certainly more effecient than your method above

btw i think the code problem above is due to the [string].replace method not being assign to a variable might work if you do [string]=[string].replace


regards

James
0
 
LVL 1

Author Comment

by:ddetering
ID: 12370216
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
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12373768
Glad i could help
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question