AW-106-klaviyo-metric

new using klaviyo
This commit is contained in:
gofnnp 2024-07-09 03:45:12 +04:00
parent 89b0939b83
commit b1882b5e68
3 changed files with 56 additions and 7 deletions

View File

@ -58,6 +58,55 @@
script.async = "";
document.head.appendChild(script);
</script>
<script>
!(function () {
if (!window.klaviyo) {
window._klOnsite = window._klOnsite || [];
try {
window.klaviyo = new Proxy(
{},
{
get: function (n, i) {
return "push" === i
? function () {
var n;
(n = window._klOnsite).push.apply(n, arguments);
}
: function () {
for (
var n = arguments.length, o = new Array(n), w = 0;
w < n;
w++
)
o[w] = arguments[w];
var t =
"function" == typeof o[o.length - 1]
? o.pop()
: void 0,
e = new Promise(function (n) {
window._klOnsite.push(
[i].concat(o, [
function (i) {
t && t(i), n(i);
},
])
);
});
return e;
};
},
}
);
} catch (n) {
(window.klaviyo = window.klaviyo || []),
(window.klaviyo.push = function () {
var n;
(n = window._klOnsite).push.apply(n, arguments);
});
}
}
})();
</script>
<!-- Klaviyo Metric -->
<!-- Yandex.Metrika counter -->
<script type="text/javascript">

View File

@ -35,16 +35,16 @@ const setUserID = (userId: string) => {
if (!checkIsAvailableYandexMetric()) return;
window.ym(metricCounterNumber, "setUserID", userId)
if (!window._learnq) return console.error("Klaviyo.Metric not found");
window._learnq.push(['identify', userId]);
if (!window.klaviyo) return console.error("Klaviyo.Metric not found");
window.klaviyo.push(['identify', userId]);
}
const userParams = (parameters: Partial<IUserParams>) => {
if (!checkIsAvailableYandexMetric()) return;
window.ym(metricCounterNumber, "userParams", parameters)
if (!window._learnq) return console.error("Klaviyo.Metric not found");
window._learnq.push(['identify', parameters]);
if (!window.klaviyo) return console.error("Klaviyo.Metric not found");
window.klaviyo.push(['identify', parameters]);
}
const reachGoal = (goal: EGoals) => {
@ -53,8 +53,8 @@ const reachGoal = (goal: EGoals) => {
window.ym(metricCounterNumber, "reachGoal", goal)
console.log("goal: ", goal);
if (!window._learnq) return console.error("Klaviyo.Metric not found");
window._learnq.push(['track', goal]);
if (!window.klaviyo) return console.error("Klaviyo.Metric not found");
window.klaviyo.push(['track', goal]);
}
type THitOptions = {

View File

@ -28,7 +28,7 @@ declare global {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ym: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_learnq: any;
klaviyo: any;
}
}