wirelab/shares-plugin

此软件包已弃用且不再维护。未建议替代软件包。

插件,为用户提供快速添加可自定义分享链接的方式。

安装: 107

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:streams-addon

2.0.0 2018-06-06 08:01 UTC

This package is not auto-updated.

Last update: 2021-02-12 19:41:04 UTC


README

⚠️ 此仓库已被弃用 ⚠️

插件,为用户提供快速添加可自定义分享链接并带有GA跟踪的方式。适用于任何设置meta_titlemeta_description的模块。

安装

composer require wirelab/shares-plugin

使用方法

  1. settings > plugins > shares plugin 中设置您的facebook应用密钥 (可选)
  2. settings > plugins > shares plugin 中选择默认启用的网络 (可选)
  3. 在您的主题中放入 {{ shares_scripts()|raw }} 以加载所有javascript文件
  4. 在任意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>

有关最新片段,请参阅 谷歌文档