Created
February 15, 2021 15:44
-
-
Save fresh5447/0ec0f6020da2f7571bd9c6e85e3663a7 to your computer and use it in GitHub Desktop.
Klaviyo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EMAIL SIGNUP FUNCTIONS | |
onSubmit() { | |
const isValidEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.email); | |
if (isValidEmail) { | |
return fetch('https://manage.kmail-lists.com/ajax/subscriptions/subscribe ', { | |
method: 'POST', | |
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | |
body: JSON.stringify({email: this.email, g: 'XYVPwG'}) | |
}) | |
.then((res) => { | |
this.signupMessage = this.staticLabel('newsletter_signup_success'); | |
this.signupStatus = 'success'; | |
console.log(res, this.signupMessage, this.signupStatus); | |
}) | |
.catch((e) => { | |
this.signupMessage = this.staticLabel('newsletter_signup_error'); | |
this.signupStatus = 'error'; | |
console.error('Form Submit Error', e, this.signupMessage, this.signupStatus); | |
}); | |
} | |
}, | |
injectKlaviyoSignupScript() { | |
let externalScript = document.createElement('script'); | |
externalScript.setAttribute('async', true); | |
externalScript.setAttribute('src', '//www.klaviyo.com/media/js/public/klaviyo_subscribe.js'); | |
document.head.appendChild(externalScript); | |
} | |
// TRACK PRODUCT EVENT | |
klaviyoViewProductEvent() { | |
const _learnq = window._learnq || _learnq || []; | |
const {id, name, defaultImage, prices} = this.productData; | |
const viewdProduct = { | |
Name: name, | |
ProductID: id, | |
ImageURL: defaultImage.url, | |
URL: window.location.href, | |
Brand: 'Oboz Footwear', | |
Price: prices.price.value, | |
CompareAtPrice: prices.isOnSale ? prices.salPrice.value : prices.price.value | |
}; | |
_learnq.push(['track', 'Viewed Product', viewdProduct]); | |
_learnq.push([ | |
'trackViewedItem', | |
{ | |
Title: viewdProduct.Name, | |
ItemId: viewdProduct.ProductID, | |
ImageUrl: viewdProduct.ImageURL, | |
Url: viewdProduct.URL, | |
Metadata: { | |
Brand: viewdProduct.Brand, | |
Price: viewdProduct.Price, | |
CompareAtPrice: viewdProduct.CompareAtPrice | |
} | |
} | |
]); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment