Developer forum

Forum » Development » RE: Open Graph Meta Tags

RE: Open Graph Meta Tags

Jeppe Jakobsen
Reply

Hello Everyone

I'm trying to implement the Open Graph Protocol (http://ogp.me/) in my current solution, so users can get a nice preview of the content when referring to the site on different social media.

As of right now i have a somewhat working solution. I use a NotificationSubscriber that simply adds tags to the current PageView, and then renders them in head on my masterpage by using @GetValue("MetaTags"), which works nicely, as this appears in my <head>.

<meta name="og:title" content="Preview Test Title" />
<meta name="og:type" content="website" />
<meta name="generator" content="Dynamicweb 8" />
<meta name="og:url" content="http://www.mywebsite.com/Default.aspx?ID=1&Purge=True" />
<meta name="og:image:secure_url" content="/Files/Templates/Designs/{design}/img/logo.png" />
<meta name="og:image" content="/Files/Templates/Designs/{design}/img/logo.png" />

If i then open a url like this: "https://www.mywebsite.com/Default.aspx?ID=1&Purge=True" or "https://www.mywebsite.com/default.aspx?AreaID=1" in a Skype conversation, the preview is shown, title, image and all, just as it should.

The problem then occurs if i only use the first part of the url, "https://www.mywebsite.com". Then a odd preview with the title "Home" and no content is shown. There are no page anywhere in my solution that uses the title "Home", either in the admin panel or solution, which leads me to believe that it hits some default page that redirects(?).

If anyone could shed some light on the problem it would be much appreciated.

 

Bonus question: When i hit a NotificationSubscriber -> OnNotify, do i at this point in the lifecycle know if the page that is being rendered is a single product? If so, i would really like to change the preview image and title to corresponding the product.


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Jeppe

@your first question: I need a URL to see that. Guaranteed that the page exist on that URL from an external location. I need to see your setup to find what is wrong.

@you bonus question: Depends on which notification subscriber you are using...? No matter which one it is, you can check if Request.QueryString("ProductID") has a value - in that case you have a product being showed.

Say you observer the Page.Loaded notification - that is raised before the product is rendered. In that you can check if the productid parameter has a value, and if not, insert your tags as you do now. Then in a product template extender, add the tags from that - IMPORTANT: remember to check that ProductTemplateExtender.IsDetailView is true (requires a very new 8.7.2)

Votes for this answer: 1
 
Jeppe Jakobsen
Reply

I think i worked out why i was having problems. It seems like all the urls i try gets cached the first time it renders the preview, and will not update its values if i update the tags on my page. So it was not strange that different links to the same page gave different results, as they all had their own cached version, so i will arm myself with some patience or figure out a way to trigger a refresh.

Your answer to the bonus question worked very well, so thanks for that.

 
Nicolai Høeg Pedersen
Reply

ok - even though you should really not see that cache.... There are 2 possibilities of cache (maybe 3). Browser cache, Dynamicweb cache and you could have a proxy server in your company that caches things.

If it is browser cache, you have some messed up settings. Do a CTRL+F5 to force the browser to do a fresh request to the server.

If it is DW cache, when you click preview in the /admin, the page is shown using &purge=true which resets any cache there might be (requires that you are logged in)

NP

 
Jeppe Jakobsen
Reply

No, not that type of cache. I used skype to preview my links, but skype doesnt seem to clear its cache for the url's very often, so i tried it on another platform. That solved everything, as i was not doing anything wrong  in the first place.

 

You must be logged in to post in the forum