Social Bookmarking - remove string

Sarah Bartell asked on September 20, 2017 16:00

We use marketo to send out email notifications to our customers whenever we post a new blog. Once a customer clicks the link from the email to the blog, the URL becomes www.company.com/blog/blog-title.aspx?mkt_tok=eyJpIjoiTnpGa01UUXpZVGd6WmpRNCIsInQiOiJGc3k4MXBMcHNsTFNydXdxYzQyeEs1RFEyazl2Wk1VdlwvS2dqUU9KVXRuUExva01tK1ByRTNZR1I4QnJ6c3llaysyT1VtenY0NzU3TWo0eUNyb09KT0JTZDMxS256R2FUdVZxQWZrbnhLb21lQ2d4SHFnNGh1RHJaTHROS0JZdmIifQ%3D%3D

with a huge string on the end of the URL so we can track the campaign clicks. So, my question is, how can I modify the social bookmarking ascx file, so that when a client goes to share the blog on Twitter, it won't populate the URL with that huge string at the end, and will just end at .aspx? Thank you in advance!

Recent Answers


Development Support Avastonetech answered on September 20, 2017 17:41

I'm trying to find the webpart you are using, it doesn't seem to be part of the default Kentico (at least not 10). What version are you on, and what is the file location so i can take a look?

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 20, 2017 18:31

We are on v8.2. The file is located in CMSWebParts/CommunityServices/SocialBookmarking.ascx.cs

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 20, 2017 19:22

Thanks Sarah, now i've found it (it was in a slightly different spot though, but hopefully the code is the same).

See if you can find this line of code:

string liveUrl = RequestContext.CurrentURL;
liveUrl = URLHelper.GetAbsoluteUrl(liveUrl);

Add two more line to it so it looks like this:

string liveUrl = RequestContext.CurrentURL;
liveUrl = URLHelper.GetAbsoluteUrl(liveUrl);
string token = "mkt_tok=" + URLHelper.GetUrlParameter(liveUrl, "mkt_tok");
liveUrl = liveUrl.Replace("?" + token + "&", "?").Replace("&" + token, "").Replace("?" + token, ""); // Handles removing JUST that parameter, without messing up other tokens.

Seems a little overkill, but this will remove JUST that token, in case other pages need the Urls (like bookmarking the 2nd page of a listing where ?page=2 is in the url and needed.

Tell me if that works!

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 20, 2017 20:24

Thank you! I implemented the code but it's still populating the string ...here's what the code looks like:

Image Text

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 20, 2017 20:42

Let's see if this is even the correct spot then. Just for a moment (change, check the link, then undo it) add the following line, i want to see if this is even the right spot:

liveUrl = "Test_"+token;

Tell me if the URL changes to Test, and then also compare the token value and the url value, can you post that back here? After you run the test, be sure to remove that line though :)

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 21, 2017 15:44

Still no dice. The token didn't change to test. This is what the URL looks like:

http://twitter.com/share?url=http%3a%2f%2fwww.merge.com%2fBlogs%2fEnterprise-Imaging-Blog%2fSeptember-2017%2fVendor-Neutrality-What-does-it-really-mean-and-wh.aspx%3fmkt_tok%3deyJpIjoiTnpGa01UUXpZVGd6WmpRNCIsInQiOiJGc3k4MXBMcHNsTFNydXdxYzQyeEs1RFEyazl2Wk1VdlwvS2dqUU9KVXRuUExva01tK1ByRTNZR1I4QnJ6c3llaysyT1VtenY0NzU3TWo0eUNyb09KT0JTZDMxS256R2FUdVZxQWZrbnhLb21lQ2d4SHFnNGh1RHJaTHROS0JZdmIifQ%253d%253d&text=Vendor+Neutrality%3a+What+does+it+really+mean+and+why+is+it+important%3f
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 21, 2017 15:49

Then we're barkign up the wrong tree. Can check to make sure we're looking at the right file? Check the page template and look at the webpart, then look up that web part and in the general tab see where the webpart's ASCX file is. Is that the one you are modifying?

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 21, 2017 16:08

We're definitely in the right file. ~/CMSWebParts/SocialMedia/SocialBookmarking.ascx.cs

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 21, 2017 16:28

Can you copy your entire ascx.cs file to pastebin.com and link me to it so i can take a look?

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 22, 2017 17:26

I have no idea how to use PasteBin. Does this work?

https://pastebin.com/jJYJQRx0

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 22, 2017 19:16

Doesn't make any sense to me why the liveUrl = "Test_"+token; at the end of the code wouldn't result in the URL changing, for the time being though to get you going, let's just remove any URL Parameters:

// Get url of current document
            string liveUrl = RequestContext.CurrentURL;
            liveUrl = URLHelper.GetAbsoluteUrl(liveUrl);
            liveUrl = liveUrl.Split('?')[0];
            //string token = "mkt_tok=" + URLHelper.GetUrlParameter(liveUrl, "mkt_tok");
            //liveUrl = liveUrl.Replace("?" + token + "&", "?").Replace("&" + token, "").Replace("?" + token, ""); // Handles removing JUST that parameter, without messing up other tokens.

Try that code there in place of the stuff we were working with, i'm just removing any url parameters ta all, tell me if that works, make sure to clear the cache as well (system-> Clear cache)

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on September 22, 2017 20:37

I hate to say it, but still no dice. :( Cleared the cache and tried a few different browsers too.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 25, 2017 16:15

I really don't think then that this is the code that's running. Last test of that is to cut out ALL hte text in that .cs file (copy it to a notepad), and see if an error appears. If the link still renders, then at that point obvious this is the not the file we are looking for.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.