Created
January 15, 2020 17:01
-
-
Save cbarley10/bf3d050b60c056fbbc4b30dca5294475 to your computer and use it in GitHub Desktop.
Hungry Bark Finished Quiz event
This file contains 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
<script> | |
var finishedQuizButton = document.querySelector("#finishedQuizButton") | |
// this is a fake button, but is an example of what you'd do to select a button with the ID of "finishedQuizButton" | |
var payload = { | |
"user": { | |
"$email": "john.smith@gmail.com", | |
"$firstname": "John", | |
"$lastname": "Smith" | |
}, | |
"dogs": [{ | |
"name":"Rusty", | |
"age": 3, | |
"breed": "mixed", | |
"weight": "30 lbs" | |
}, | |
{ | |
"name": "Bailey", | |
"age": 4, | |
"breed": "lab", | |
"weight": "50 lbs" | |
}] | |
} | |
var IdentifyUser = function(data){ | |
var user = data.user; | |
// Make Identify Request to Klaviyo with info about the user and any custom properties you might want to add. | |
_learnq.push(["identify", { | |
"$email": user["$email"], | |
"firstname": user["$firstname"], | |
"$lastname": user["$lastname"], | |
// info about that user's dog can also go here, which will show up on the Klaviyo Profile as Custom Properties | |
}]) | |
} | |
var sendEventToKlaviyo = function(data){ | |
var dogs = data.dogs; | |
_learnq.push(["track", "Finished Quiz", dogs]) | |
} | |
function fireBoth(){ | |
IdentifyUser(payload) | |
sendEventToKlaviyo(payload) | |
} | |
finishedQuizButton.addEventListener("click", fireBoth, false) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment