wirelab / shares-plugin
此软件包已弃用且不再维护。未建议替代软件包。
插件,为用户提供快速添加可自定义分享链接的方式。
2.0.0
2018-06-06 08:01 UTC
README
⚠️ 此仓库已被弃用 ⚠️
插件,为用户提供快速添加可自定义分享链接并带有GA跟踪的方式。适用于任何设置meta_title
和meta_description
的模块。
安装
composer require wirelab/shares-plugin
使用方法
- 在
settings > plugins > shares plugin
中设置您的facebook应用密钥 (可选) - 在
settings > plugins > shares plugin
中选择默认启用的网络 (可选) - 在您的主题中放入
{{ shares_scripts()|raw }}
以加载所有javascript文件 - 在任意twig文件中调用
{{ shares({title: '', url: '', description: '', networks: ['']|raw }}
所有参数都是可选的
参数
名称 | 描述 | 可选 | 默认值 | 类型 |
---|---|---|---|---|
title | 分享中使用的标题 | 是 | template.meta_title | 字符串 |
description | 分享中使用的描述 | 是 | template.meta_description | 字符串 |
url | 分享得到的url | 是 | 当前url | 字符串 |
networks | 要返回的社会媒体网络列表 | 是 | 全部 (可在设置中配置) | 数组 |
启用facebook分享
使用javascript设置以下cookie:cconsent=isAccepted
。然后调用 callCbIfConsentGiven(callback)
。
示例
{{ shares() }} {# Guessing all data #} {{ shares({'networks':['twitter','facebook']}) }} {# Limiting to certain networks #} {# Manually setting data #} {{ shares({ 'title': 'Wirelab', 'description': 'The website of Wirelab', 'url': 'http:://www.wirelab.nl' }) }} {{ shares_data() }} {# Get an array of all data instead of views #}
添加谷歌分析
将以下代码添加到 <head>
标签的顶部附近。将 UA-XXXXX-Y
替换为您要跟踪的谷歌分析属性的属性ID(也称为“跟踪ID”)。
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://#/analytics.js','ga'); ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview'); </script>
有关最新片段,请参阅 谷歌文档