reactjs - 如何在 gatsby 的特定页面上实现 zendesk Web 小部件
问题描述
将 zendesk 安装脚本添加到html.js
文件中按预期工作,并且小部件显示在所有页面上。
我想在特定页面上显示它,例如about-us
页面。我试过这个
render() {
return (
<>
<script
id="ze-snippet"
src="https://static.zdassets.com/ekr/snippet.js?key=xxx-xxxxx"
>
</script>
...
</>
但它不起作用。任何想法?
解决方案
在 index.html 文件中
<html>
<body>
<!-- your scripts -->
<script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key={YOUR_KEY}"> </script>
<!-- Hide de widget by default -->
<script>zE('webWidget', 'hide')</script>
</body>
</html>
在您的组件中显示
import React from 'react'
class MyComponent extends React.Component {
constructor (props) {
super(props)
}
componentDidMount () {
// show widget on mount component
zE('webWidget', 'show')
}
componentDidUnmount () {
// hide widget on unmount component
zE('webWidget', 'hide')
}
render () {
// your render
return (
<div>Hello World</div>
)
}
}
在其他组件中无需执行任何操作
推荐阅读
- bash - 如何查找文件中两个第一个单词与上一行和下一行不同的行
- java - Java 自定义转义字符
- ruby - {|_, e| e.length>1} Ruby 中下划线(_)的用途是什么?
- tableau-api - tableau grant total 没有给我计算字段的正确输出
- spring - 弹簧反应器异常
- reactjs - Android 后退按钮无法按预期工作
- php - 如何从多个项目和数组中获取 PHP 中的唯一输出
- python - python argparse 限制 arg 值操作 API?
- java - 使用 JNA 获取单个像素的颜色
- octave - 从包含标题的文件中读取矩阵