var respondent_id = "^CurrentID()^";
//console.log("respondent_id: " + respondent_id);
//PIPE THE CORRECT params_id based on CELL (1 or 2)
var cellParamID = "";
var Qcell = "^f('cell').value()^";
//console.log(Qcell);
if (Qcell == 1) {
cellParamID = "PRMS01G3H5QXCJ252E6FK650KEGB0Y";
} else if (Qcell == 2) {
cellParamID = "PRMS01G3H4T858PQD3K1FF04P3C64D";
} else if (Qcell == 3) {
cellParamID = "PRMS01G3RTH7CHX4X160AMHK4G95H0";
} else if (Qcell == 4) {
cellParamID = "PRMS01G3H5GZEMTF7GX9SYS00TDDM2";
}
//Get survey ID from Param ID -------------------------------------
var paramsCallObj = {
event_type: "params_crud",
action: "get_params",
data: {
params_id: cellParamID,
},
};
var paramsCallStr = JSON.stringify(paramsCallObj);
var surveyIDcall = $.parseJSON(
$.ajax({
url: "https://better-params-api.rose.conceptsauce.io/api",
type: "POST",
data: paramsCallStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success id call");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
//console.log("out");
var survey_id = "";
if (surveyIDcall.code == 200) {
survey_id = surveyIDcall.data.params.survey_id;
}
//console.log("survey ID: " + survey_id);
//get SUMMARY -----------------------------------------------------
var surveyIdCallObj = {
event_type: "survey_data_request",
action: "get_shop_shelf_summary_purchases",
data: {
target: {
survey_id: survey_id,
respondent_id: respondent_id,
block_id: "shelf",
},
},
};
var surveyIdCallStr = JSON.stringify(surveyIdCallObj);
var resultAPIcall1 = $.parseJSON(
$.ajax({
url: "https://public-survey-data-api.rose.conceptsauce.io/api",
type: "POST",
data: surveyIdCallStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success api call SUMMARY");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
//console.log("SUMMARY OUT");
//console.log(resultAPIcall1);
//Get all SKUs and append them into the variable
var P1summarySku = Confirmit.page.getQuestion("P1SKUs");
P1summarySku.setValue(null);
var P1SKU = resultAPIcall1.data.basket_summary.sku_list;
//console.log("SKU LIST BELOW");
//console.log(P1SKU);
P1summarySku.setValue(P1SKU);
// get DETAILS ---------------------------------------------------------
var reqBodyDetails = {
event_type: "survey_data_request",
action: "get_shop_shelf_detail_purchases",
data: {
target: {
survey_id: survey_id,
respondent_id: respondent_id,
block_id: "shelf",
},
},
};
var reqBodyDetailsStr = JSON.stringify(reqBodyDetails);
var resultAPIcall2 = $.parseJSON(
$.ajax({
url: "https://public-survey-data-api.rose.conceptsauce.io/api",
type: "POST",
data: reqBodyDetailsStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success api call DETAILS");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
var rawPurchaseDet = resultAPIcall2.data.basket_details.raw_purchase_details;
//Get quantity for each SKU
var SkuQuant = [];
for (var z = 0; z < rawPurchaseDet.length; z++) {
SkuQuant.push(rawPurchaseDet[z].quantity);
}
var SkuQtity = Confirmit.page.getQuestion("P1Quant");
SkuQtity.setValue(null);
SkuQtity.setValue(SkuQuant);
//Set total time spent at the shelf
var P1shelfTime = Confirmit.page.getQuestion("P1ShelfTime");
P1shelfTime.setValue(null);
P1exDur = resultAPIcall2.data.exercise_duration;
P1shelfTime.setValue(P1exDur);
//get summary ITEMS looked at
var reqSumItems = {
event_type: "survey_data_request",
action: "get_shop_shelf_summary_items_looked_at",
data: {
target: {
survey_id: survey_id,
respondent_id: respondent_id,
block_id: "shelf",
},
},
};
var reqSumItemsStr = JSON.stringify(reqSumItems);
var resultAPIcall3 = $.parseJSON(
$.ajax({
url: "https://public-survey-data-api.rose.conceptsauce.io/api",
type: "POST",
data: reqSumItemsStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success api call Summary Items");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
//console.log("Summary Items looked OUT");
//console.log(resultAPIcall3);
//recode all items looked at(bought and not bought, abe vsi4ki)
var itemsLookedAt = resultAPIcall3.data.items_looked_at;
var P1look = Confirmit.page.getQuestion("P1looked");
P1look.setValue(null);
var P1lookArr = [];
for (var p = 0; p < itemsLookedAt.length; p++) {
P1lookArr.push(itemsLookedAt[p].sku);
}
//console.log(P1lookArr);
P1look.setValue(P1lookArr);
// Get Details Looked at
var reqDetLooked = {
event_type: "survey_data_request",
action: "get_shop_shelf_detail_items_looked_at",
data: {
target: {
survey_id: survey_id,
respondent_id: respondent_id,
block_id: "shelf",
},
},
};
var resultDetLookedStr = JSON.stringify(reqDetLooked);
var resultAPIcall4 = $.parseJSON(
$.ajax({
url: "https://public-survey-data-api.rose.conceptsauce.io/api",
type: "POST",
data: resultDetLookedStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success api call Details looked");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
//console.log("Details looked Items OUT");
//console.log(resultAPIcall4);
//Get Findability details
var reqFindability = {
event_type: "survey_data_request",
action: "get_findability_details",
data: {
target: {
survey_id: survey_id,
respondent_id: respondent_id,
block_id: "shelf",
},
},
};
var reqFrindabilityStr = JSON.stringify(reqFindability);
var resultAPIcall5 = $.parseJSON(
$.ajax({
url: "https://public-survey-data-api.rose.conceptsauce.io/api",
type: "POST",
data: reqFrindabilityStr,
dataType: "json",
async: false,
success: function (result) {
console.log("success api call Findability");
console.log(result);
},
error: function (error) {
console.log(error);
},
}).responseText
);
//console.log("Findability OUT");
//console.log(resultAPIcall5);
$(document).ready(function () {
$(".cf-navigation-next").click();
});
|