Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JavaScript Document
- // Initialize Firebase
- var config = {
- apiKey: "AIzaSyDuQZCwIWwWO8SftZHHVax3eNmwvy6YGj0",
- authDomain: "captiate-variables.firebaseapp.com",
- databaseURL: "https://captiate-variables.firebaseio.com",
- projectId: "captiate-variables",
- storageBucket: "captiate-variables.appspot.com",
- messagingSenderId: "844765632528"
- };
- firebase.initializeApp(config);
- var firestore = firebase.firestore();
- const docRef = firestore.collection("variables").doc("spkoOZ4GZloduEGIYTxM");
- //listen for Captivate to tell us it's loaded and ready
- window.addEventListener("moduleReadyEvent", function(evt) {
- //evt.Data carries the interface object.
- //It is same as window.cpAPIInterface
- var interfaceObj = evt.Data;
- var eventEmitterObj = interfaceObj.getEventEmitter();
- //listen for variable change
- cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",
- function(){updateVariable(
- "variables",
- "spkoOZ4GZloduEGIYTxM",
- "hotDogStatus",
- window.cpAPIInterface.getVariableValue("v_visited")
- )},"v_visited");
- });
- function updateVariable(collection, doc, variable, newValue){
- firestore.collection(collection).doc(doc).set({
- variable: newValue
- }).then(function() {
- console.log("Document "+ variable +" successfully updated to: " + newValue);
- }).catch(function(error) {
- console.error("Error writing document: " + variable, error);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement