amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-social-share template components for social sharing buttons

Open niallkennedy opened this issue 10 years ago • 24 comments

Social sharing buttons commonly appear alongside article content to assist a viewer interested in sharing a page or article to a social network or messaging service. Publishers place buttons on their page to encourage sharing by reducing friction with specified precomposed share template components.

Share buttons often appear in a shared content unit with multiple buttons displayed in a consistent template or official buttons from each social network. An individual share button should be easily recognizable to the audience of a social network.

Common options

Custom share button

custom-share-buttons

A custom button places a social network logo on a background color solidifying the brand identity of the sharing site (light blue for Twitter, light red for Google+, etc.). A share verb specific to the social network might be included as visible inner text or a title attribute, localized to the language of expected viewers. A custom button creates a link to a share form on the social network site with precomposed share template components.

Custom share button styling would live inside the framework with share parameters provided in the AMP HTML document.

Supported parameters

Site text url image attribution
Twitter text url via
Pinterest description url media
Facebook href app_id
Google+ url
LinkedIn title url source
Weibo title url pic appkey

Official share button

official-share-buttons

An official share button adds an externally-hosted JavaScript file or iframed button content. The button is instantly recognizable as a consistent share graphic across the Web. The button JavaScript may populate share template components based on the existing markup of the page, such as a link canonical href attribute or title element inner text. Share button JavaScript may dynamically load an always updated translated share verb to improve sharing. Share button JavaScript may manage share dialog child windows depending on the size of the display area (less common on mobile).

An official share button may include additional remote analytics requests to log use of the product, audience profiling, etc.

Proposal

Social sharing provider

A social sharing provider specifies a background color and vector graphic to be used to style a social sharing button in a displayed AMP page.

A share URL endpoint and expected query parameters are provided by the sharing provider to build the needed sharing URL. Required, optional, and non-supported common share object properties may be defined. Input validations may be defined similarly to an HTML element (type=text, maxlength=140; type=number, min=1, max=5; etc.).

{
  "text": {
    "param": "text",
    "required": false,
    "type": "text",
    "maxlength": 140,
  },
  "attribution": {
    "param": "via",
    "required": false,
    "type": "text",
    "maxlength": 20,
  }
}

A provided configuration object without the required parameters will result in the omission of the social sharing button.

A shared text element exceeding a maxlength will be truncated to maxlength - 1 with an inserted horizontal ellipsis (U+2026).

Publisher

A publisher specifies a custom element with a social sharing provider identifier and a JSON object containing configuration parameters.

<amp-social-share type="twitter">
{
  "text": "Hello world",
  "url": "https://example.com/",
  "attribution": "AMPhtml"
}
</amp-social-share>

If omitted, the url property will be populated by the link canonical of the page.

niallkennedy avatar Dec 18 '15 22:12 niallkennedy

as mentioned to @paul-matthews, wondering if publishers are more likely to implement an official button or custom styled buttons for social sharing actions. If the social sharing template component is common enough it could become supported in AMP.

niallkennedy avatar Dec 18 '15 22:12 niallkennedy

Totally agree we should build this – even if strictly speaking this can be done directly in AMP (although for desktop one would often want a popup instead of target=_blank).

I think we should not support the "official share buttons". Especially Twitter which no longer has a count provides little value over a straight up inline button and FB and G+ are pretty heavy for the value they provide.

Some publishers use "count providers". Basically web services that scrape share counts from more or less official APIs or non-APIs and display them with the buttons. I wonder if we should offer that as an option.

@rudygalfi

cramforce avatar Dec 20 '15 22:12 cramforce

I'm currently working on a prototype / first pass at building this. Hope to share it here by EOW.

paul-matthews avatar Jan 11 '16 18:01 paul-matthews

In the implementation, I use SVGs for the share icons. For consistency I plan to use the following MIT licensed implementation of the SVGs in the codebase: http://codepen.io/anon/pen/KVZNGp

I'll be checking them into 3p, then use the generators to import them inline at build time.

paul-matthews avatar Jan 21 '16 22:01 paul-matthews

What's the reason for mixing a HTML element with JSON like this as opposed to using attributes or child elements to achieve the same effect? Is the "style" documented somewhere?

Primigenus avatar Jan 26 '16 00:01 Primigenus

I chose JSON in my example to match the amp-analytics work happening at the time, which combines JSON and the custom element.

niallkennedy avatar Jan 26 '16 00:01 niallkennedy

We typically use JSON when there are more than a few options. Its pretty popular over nested config-only markup.

I could very much see using child tags here, though, since they'd actually have their equivalent visual representation.

cramforce avatar Jan 26 '16 00:01 cramforce

I implemented this with embeded JSON however it does mean that if the element fails to load there's raw JSON left visible in the page.

paul-matthews avatar Jan 27 '16 22:01 paul-matthews

We typically place json into a script tag e.g.:

<element>
  <script type="application/json">
    {
    }
  </script>
</element>

This has two main benefits:

  1. JSON is not visible if anything fails
  2. You don't need HTML escapes when authoring JSON. E.g. you don't need to do a&amp;b, but instead a&b.

dvoytenko avatar Jan 28 '16 17:01 dvoytenko

Design decision:

  • the element now supports both:
    • embedded JSON in script tag
    • element data attributes

paul-matthews avatar Mar 02 '16 23:03 paul-matthews

@niallkennedy #1856 has been merged if you'd like to check it out.

If you just want to see it working, I've staged an example at https://amp-partners.appspot.com/social

paul-matthews avatar Mar 10 '16 01:03 paul-matthews

@paul-matthews trying to use social-share script and it is broken (not validating and telling me I cant use amp-social-share). even the demo page is invalidating https://amp-partners.appspot.com/social#development=1

Not sure if its related to the .max.js CDN 404ing ? https://github.com/ampproject/amphtml/pull/2686/files

Any thoughts? Thanks.

mannynotfound avatar Mar 24 '16 18:03 mannynotfound

@artnotfound The 404 is not related - it was a typo. The validator work has not been completed, and that's why you are seeing validation errors.

@Gregable could you please update on validator and link the tracking issue if available?

dvoytenko avatar Mar 24 '16 20:03 dvoytenko

Currently needs:

Move to experimental (and indicate in .md that this is in experimental): #2672 Validation (needs link to tracking issue) Namespaced classes: #2668

Are there any other open issues for this component?

ericlindley-g avatar Mar 28 '16 22:03 ericlindley-g

@ericlindley-g Namespace classes is very important for release. Let's assign right away.

dvoytenko avatar Mar 29 '16 17:03 dvoytenko

Hi, sorry to jump into this discussion. We'd love to have social sharing buttons for our amp pages but our Audience is coming from Russia and Asia where Facebook and Twitter are not the leading social platforms. Would it be possible for you to add the Vkontakte sharing button? Baidu would also be a good addition but Weibo should already cover a big part of this user segment.

https://vk.com/dev/share_details http://d.baidu.com/search/cang_help.html

vkontakte: http://vkontakte.ru/share.php?url=[URL]&title=[TITLE]&description=[DESCRIPTION]&image=[IMAGEURL]&noparse=true baidu: http://cang.baidu.com/do/add?iu=[URL]&it=[TITLE]

jayston avatar Mar 30 '16 09:03 jayston

@jayston I started a new issue to track further enhancements to amp-social-share: #2756.

rudygalfi avatar Mar 30 '16 16:03 rudygalfi

Hi! Are there any sort of style restrictions around the custom buttons? We’d love if these could be branded to work well with the rest of an article design or sit back visually so they're not too distracting for readers.

Aetherpoint avatar Apr 04 '16 19:04 Aetherpoint

@Aetherpoint , you should be able to customize your buttons as needed (you can refer to the .md file for how to do that), but feel free to request styling or functionality that isn't available

ericlindley-g avatar Apr 04 '16 19:04 ericlindley-g

@ericlindley-g – Great, thank you!

Aetherpoint avatar Apr 04 '16 19:04 Aetherpoint