Vincent Taing
Vincent Taing

Reputation: 3334

Mailchimp Facebook share URL doesn't redirect to correct URL

I am trying to use providing a variable to Facebook share plugin in Mailchimp. I want to share this URL :

https://www.example.com/#!/campaign/5577fc135257be030087f44b/landing

I am using JavaScript so I encoded the URL with encodeURIComponent(uri) which enables me to use Facebook Share:

https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.example.com%2F%23!%2Fcampaign%2F555ee391c95a870300616317%2Flanding

The Facebook Share Dialog shows up correctly. However it only shares www.example.com, the rest of the url has been stripped out.

What did I do wrong ?

Upvotes: 1

Views: 256

Answers (1)

Valentin Waeselynck
Valentin Waeselynck

Reputation: 6051

2 pitfalls to be aware of here:

  1. Surprisingly enough, Mailchimp's social share content blocks won't URL-encode your link when building the Share URL. So as you proposed, you need to URL-encode it yourself.
  2. JavaScript's encodeURIComponent is not exactly what you want here, because it will not escape the exclamation mark (!), as well as a few other characters that have special meaning in URLs (see MDN reference). Replacing the ! by %21 in your link would make it work.

Sadly I haven't found a JavaScript library that does this URL-encoding reliably (url doesn't), you'll probably want to replace the ! manually.

Upvotes: 1

Related Questions