Reputation: 1573
End result: I'm trying to fix an issue with Disqus reading links with UTM URL parameters as separate pages from the clean URL.
Back story: When Disqus was originally installed on this site on HubSpot, no options were set other than the forum shortname. When readers visit blog posts directly or via a clean URL with no tracking parameters, they'll see the correct Disqus comments thread. But if they visit the post with a "dirty" URL with a bunch of tracking parameters, such as one of the ones sent with our email subscription, they'll see a Disqus comment thread associated with that specific URL.
Obviously, we want people who visit via the email link to be able to see the same comments thread as the people who visit via our own site.
The way I'm thinking of solving this is to use the xxxxxxxxx
part of the hs-content-id-xxxxxxxxx
class in the <body>
to set the disqus_identifier
:
var hsbody = document.body.classList;
var hsid = hsbody.item(0);
var disqus_identifier = hsid.replace("hs-content-id-", "");
This raises some questions and concerns:
disqus_identifier
. Thoughts?Limitations: I can't disable tracking codes for the emails (though that would be the easiest way to do this). We don't have a dev site, so this is all live, so I'd rather not do too much guesswork here (though I can obviously revert easily).
Upvotes: 1
Views: 129
Reputation: 1573
Since the disqus_identifier
is set to the page URL if it's undefined, I just set it to the page’s canonical URL. I can’t lose!
var canonical = "";
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i ++) {
if (links[i].getAttribute("rel") === "canonical") {
canonical = links[i].getAttribute("href");
}
}
var disqus_identifier = canonical;
Yeah, it’s pretty gross. If you’d like to refine it, please be my guest. Seems to work, though.
Upvotes: 1