哈克重现SDK
安装
npm install @hackler/react-sdk --save
yarn add @hackler/react-sdk
使用量
初始化
import { createInstance, HackleProvider } from "@hackler/react-sdk"
const hackleClient = createInstance("YOUR_SDK_KEY")
const user = {
id: "ae2182e0",
properties: {
app_version: "1.0.1",
age: 23,
paying_customer: true
}
}
ReactDOM.render(
<HackleProvider hackleClient={hackleClient} user={user} timeout={1000}>
<YourApp />
</HackleProvider>,
document.getElementById("root")
)
这个 user 取代当前用户的道具
这个 user 道具只有在其价值自上次应用以来发生变化时才适用(或
hackleClient 而不是仅仅因为道具存在。 何时
它被应用,它 替换 ,而不是合并到它。 属性合并
当两者都 userId 财务报告和审定财务报表 deviceId 不变——仅以当地评价方式;在远距离评价中
模式。 如果任一标识符不同,则丢弃上一个用户
完全没有.
这意味着道具和必须的API互相覆盖. 选一:
// Imperative — do not pass the `user` prop
const hackleClient = createInstance("YOUR_SDK_KEY")
hackleClient.setUserId("ae2182e0")
// Declarative — do not call setUserId/setDeviceId/resetUser
<HackleProvider hackleClient={hackleClient} user={user}>
<YourApp />
</HackleProvider>
混合他们丢失的数据。 如果应用程序通过 user={{ deviceId }},电话 setUserId("ae2182e0"),以及
然后用一个 user 其价值已发生变化的道具——一种附加财产,例如:
应用程序将替换用户,而用户ID已消失。 这同样适用于 resetUser(): 登录
电话不能被后来的重新发送所取消 user 道具值不变,但因
重新交代其价值已经改变的值.
缺取道具(null编号 :undefined),后来又以之前的同样价值回来
不再应用,因为跟踪的是最后一个值: 曾经 应用,而不是当前
道具 (英语). 这是刻意的:它让一个无关紧要的切入器从擦出 setUserId 通话时
道具不见了.
提供者按值来比较道具,所以一个不稳定的参照物——内置对象字形,如:——
只要它的财产价值是原始的或原始的数组,它就不需要付出任何代价
sDK会接受的 当一个属性值是嵌入对象时,稳定引用才重要:
以参考方式比较,否则将重新应用每个参数。 通过道具作为稳定的参考
在这种情况下——模块镜常数,或 useMemo 当生成时:
const user = useMemo(() => ({ id: userId, properties: { plan } }), [userId, plan])
如果您只需要一个启动用户而从未更新过,请传递给 createInstance 转而下降
道具 :
const hackleClient = createInstance("YOUR_SDK_KEY", {
user: { id: "ae2182e0", properties: { plan: "premium" } }
})
决定变化
function App() {
return (
<HackleExperiment experimentKey={42}>
<HackleVariation variation={"A"}>
<OldBlueButton />
</HackleVariation>
<HackleVariation variation={"B"}>
<NewRedButton />
</HackleVariation>
</HackleExperiment>
)
}
记录活动
const track = useTrack()
const event = {
key: "purchase",
value: 5000,
properties: {
first_paying: false,
item_count: 5
}
}
<button onClick={() => track(event)}>Purchase</button>