Skip to content

Instantly share code, notes, and snippets.

@michaeldegli
Last active March 16, 2022 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save michaeldegli/31b0257a037bd79d2c34 to your computer and use it in GitHub Desktop.
Save michaeldegli/31b0257a037bd79d2c34 to your computer and use it in GitHub Desktop.
Tracking time on slide with Veeva Clickstream object using JavaScript
//First thing: get the product SFID
function prod_callback(result) {
prod_id_array.push(result);
}
com.veeva.clm.getDataForCurrentObject("KeyMessage", "Product_vod__c", prod_callback);
function track(arr) {
var prod_id;
var obj = {
"Track_Element_Id_vod__c": "undefined",
"Track_Element_Description_vod__c": "undefined",
"Usage_Duration_vod__c": 0,
"Answer_vod__c": "",
"Usage_Start_Time_vod__c": new Date()
};
if (prod_id_array.length > 0) {
if (prod_id_array[0].success === true) {
obj["Product_vod__c"] = prod_id_array[0].KeyMessage.Product_vod__c;
}
}
function init_callback(result) {
data.push(result);
}
//init_callback(page);
com.veeva.clm.createRecord("Call_Clickstream_vod__c", obj, init_callback);
var pages = data.length;
//console.log(pages);
var save = function() {
var num = 0;
return setInterval(function() {
num++;
//this.tracking_object[name].time = num;
obj["Track_Element_Id_vod__c"] = arr[0];
obj["Answer_vod__c"] = arr[0]; //so reps can see their page history on call reports
obj["Track_Element_Description_vod__c"] = arr[1];
obj["Usage_Duration_vod__c"] = num;
function callback(result) {
update_result[0] = result;
}
com.veeva.clm.updateRecord("Call_Clickstream_vod__c", data[pages].Call_Clickstream_vod__c.ID, obj, callback);
//callback(JSON.stringify(obj));
}, 1000);
};
if (interval.length > 0) {
clearInterval(interval[0]);
}
//wait for the create object to return
setTimeout(function() {
interval[0] = save();
}, 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment