How to trigger data collection with SiteCatalyst? - javascript

I just get started with Adobe SiteCatalyst and I am just wondering how could I trigger the sending of colllected data to the server with it.
Imagine the situation that I have some custom event, for example event1 = 'user opened help us popup'. After user opens popup - I'm assigning data to props:
s.events = "event1";
s.prop1 = "name of popup";
After that I'm checking the analytics debugger (https://www.adobetag.com/d1/digitalpulsedebugger/live/DPD.js) and it says that I didn't get this data.I suppose that I need somehow send it to SiteCatalyst, but I can't figure out how. Please help me.

There are two triggers for Adobe Analytics: page view s.t() and click/event s.tl()
Based on your scenario, you are probably going to want to use the s.tl() trigger.
Here is an example of what the code should look like:
s.events = "event1";
s.prop1 = "name of popup";
s.linkTrackVars = "events,prop1";
s.linkTrackEvents = "event1";
s.tl(true,'o','popup opened');
The vars you want to be tracked in the s.tl() call should be listed in linkTrackVars. If there is more than one, delimit with a comma (no spaces, no s namespace). If you have any events to track, you must also specify the events in s.linkTrackEvents. Basically, s.linkTrackEvents should be the same value as s.events (except if you are serializing an event, do NOT include the serialization ID in s.linkTrackEvents)
As for the s.tl() call, above is an example of what you might pass for a general event, but args will vary depending on what you are trying to track. (refer to link for details).

Related

in DialogFlow Messenger using inline editor for fulfillment, setContext() is interfering with setFollowupEvent()

I have an intent for password reset within DialogFlow using a one time password. You tell DF that you want to reset your password, it asks for your LAN ID, it sends an email with a short code to your email of record, you enter the code, and if it's correct, you can reset your password.
After you give your LAN ID, it sets context and triggers a follow up event "verifyCode" which prompts you for the code and then compares it to the stored value. If correct, then it sets context and triggers another follow up event.
It works perfectly in the web integration and the "try it now" box, all the way through, but not in the DialogFlow Messenger integration, where it looks like setting context interferes with the setFollowupEvent function, although it does send the email. I have tested it and if I disable the context setting the follow up event fires, but that's not helpful.
Below is the relevant code and console values.
function sendOneTimePassword(agent){
var lanIdParam = request.body.queryResult.outputContexts[0].parameters.lanId;
var lanId = lanIdParam.toLowerCase();
var user = userList[lanId];
if (user == null){
agent.add("We could not find a user with that lan ID. Please try again.");
} else {
var emailAddress = user.email;
var code = generateOneTimePassword();
var deadline = generateExpirationTime();
sendResetMail(emailAddress, code);
agent.add("Just a moment, please...");
console.log("code = "+code);
agent.setContext({
"name": 'projects/BOTNAME/agent/sessions/STRINGOFTEXT/contexts/verify',
"lifespan": 5,
"parameters":{"code": code, "deadline": deadline, "lanId": lanId}
});
agent.setFollowupEvent("validateCode");
}
}
If I remove the setContext method above, the follow up event fires, but then I have no context.
I can see that you are attempting to trigger a verification event [1] but it sometimes fails.
This may be due to how 'setFollowupEvent' works. As you can see here [2], a similar issue where 'setFollowupEvent' caused 'agent.add' to be skipped over, therefore it may not be triggering as you would expect it to.
Instead of setting context, events may instead require event parameters to be set [3].
Sample Node.js code for how to properly use events can be seen here [4].
[1] https://cloud.google.com/dialogflow/docs/events-overview#config
[2] https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/102#issuecomment-410088688
[3] https://cloud.google.com/dialogflow/docs/events-custom#webhook
[4] https://github.com/dialogflow/dialogflow-fulfillment-nodejs/blob/master/test/webhook-v2-test.js#L348

Fire Event on Background Change

Just the background:
(not really related to the question)
I am using SharePoint and creating a Sharepoint Hosted App.
I have some fields which provide a peoplepicker with which I can select Users out of a user pool. The functioninality is provide by the SharePoint internal scripts.
If I input a name of a user via jquery nothing happens. It has no built-in change handler I guess.
What I have done is a separat script which just resolve the user names on my jquery input via trigger("change") and then the SharePoint internal Scripts doing the job. This "job" is asynchronous and then if the data arrives from the backend the SharePoint Scripts apply the data to the Peoplepicker fields.
But this functions also doesn't support jQuery's trigger because I cannot alter the functions as they're pre-defined...
So want I want to do is to monitor when the text inside the Peoplepicker fields has been changed but I am a little bit lost now.
Question:
I have tried it with the following code (which doesn't work):
$('.peoplePickerDiv').bind("DOMSubtreeModified", function () {
alert("HAS BEEN CHANGED!");
});
Is there another way to react on lets say background editing of input fields in my DOM?
For People Picker control manipulation SPClientPeoplePicker object (clientpeoplepicker.js) is intended, which provides methods for getting information from the picker or to perform other operation.
SPClientPeoplePicker class exposes the following events:
OnControlValidateClientScript - triggers after a server error is set or cleared
OnUserResolvedClientScript - triggers once the resolved user is added or removed in client
OnValueChangedClientScript - triggers after text input or users change in client
OnValueChangedClientScript event probably suits your scenario, here is an example on how to attach it:
var picker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerId];
picker.OnValueChangedClientScript = function (elementId, userInfo) {
if(userInfo.length > 0){ // once the value is resolved it could be retrieved via `userInfo` object
console.log(userInfo[0]);
}
console.log('value changed');
};
References
Use the client-side People Picker control in SharePoint-hosted SharePoint Add-ins

jquery ajax call getting old data when re-used

I have an ajax call that builds a small graph in a popup window. The html for the link is re-used in many different links for different devices on the page. What happens, is that when you click a graph for the first device, you get that device. You click a button for the second device, you get that device, however, if you keep clicking away, after the third click or so, you suddenly start getting only the first device, over and over. I think my variables are being cached in some odd way, and I don't understand:
the HTML:
<a class="bluebtn graphbutton ingraph" href="http://wasat/cgi-bin/rrdjson.cgi?res=3600&start=-24h&end=now-1h&uid=28.7B2562040000" data-uid="28.7B2562040000" data-name="Laundry Room Freezer"></a>
<a class="bluebtn graphbutton ingraph" href="http://wasat/cgi-bin/rrdjson.cgi?res=3600&start=-24h&end=now-1h&uid=28.F7A962040000" data-uid="28.F7A962040000" data-name="Garage Temp"></a>
The code in question:
$(document).ready(function() {
$('.graphbutton').click(function(e) {
var formURL = $(this).attr("href");
var uid = $(this).data("uid");
var name = $(this).data("name");
e.preventDefault();
$.ajax({
url: formURL,
dataType: "json",
cache: false,
context: this,
success: function(data){
console.log("calling mkgraph with uid "+uid+" name " +name);
make_graph(data.data, uid, name);
},
error: function(ts) {
console.log(ts.responseText); }
});
}); /* clickfunc */
}); /*docready */
What happens:
Click freezer:
"calling mkgraph with uid 28.7B2562040000 name Laundry Room Freezer"
Click Garage:
"calling mkgraph with uid 28.F7A962040000 name Garage Temp"
Click Garage again:
"calling mkgraph with uid 28.7B2562040000 name Laundry Room Freezer"
Some of these links are being manufactured by the make_graph() function. I'm a bit worried that this is the issue, and somehow the ajax thing needs to be re-initialized after doing this?
By request, the relevant code in make_graph() that I think is causing my issue here. Basically, I'm editing the buttons in the css popup on the fly, and I think this is creating a wierd situation where the ajax binding is bound to the old href, and not being updated, even though the link is correct in the produced html. This is consistent with the effect where the binding only gets mangled on the third attempt.
$(".ingraph").each(function() {
this.href = $(this).attr("href").replace(/uid=.*/g, 'uid=' + uid);
this.setAttribute('data-uid' ,uid);
if (devname.length > 0) {
this.setAttribute('data-name', devname);
}
});
EDIT: adding a long answer:
I have multiple buttons on the main page. Each one specifies a "uid" that gets fed to rrdjson.cgi, which takes the uid and finds the data for that device, and returns it as json. When make_graph() recieves this json data, it populates a css popup, with the graph, and edits 5 buttons so they reference that UID. Those 5 buttons change the timescale of the graph by re-requesting the data from rrdjson.cgi.
What I am worried is happening, is that I click on the frige, it changes the uid's of the buttons inside the popup to reference the frige. Then I close that, click on the garage, it also changes the uid's and correctly shows the garage data. Then I click on one of the buttons inside the popup for the garage, and poof, I get the refrigerator again. I suspect that ajax "remembers" the old values for $(this).attr("href") etc and passes those values to the code, rather than re-reading the contents of the HTML. (perhaps instead of HTML, I meant DOM there, I'm a little vauge on the difference, but I suspect I meant DOM)
Maybe the answer is to somehow un-register the ajax binding to those buttons and re-register it every time make_graph() changes them? How would I do the un-register? .off() ? .unbind() ?
After much gnashing of teeth, and google, I have answered my own question.
https://forum.jquery.com/topic/jquery-data-caching-of-data-attributes
Turns out, jquery caches "data" types, but not attr types. So when I do:
uid = $(this).data("uid");
vs
uid = $(this).attr("data-uid");
I get wildly different results. I guess the moral of the story is that .data is super evil.. :)
If you add a random value to your url like
var formURL = $(this).attr("href")+"?rv="+Math.random();
you'll force the ajax call to reload the URL. You can use the cache property (set it to false) JQuery will load the data again, but any proxy may send a cached version.
(Please check that there are no other attributes set in the url, otherwise set "&rv="+Math.random(); (& instead of ?) use
var formURL = $(this).attr("href");
formURL + (formURL.indexOf("?") > 0 ? "&rv=" : "?rv=" )+ Math.random();
Your problem should not have something to do with make_graph() as uid and name depend on $('.graphbutton')
(if not make_graph(), or some other function, changes the attributes of your buttons)

NetSuite - Fields are not being set in the sales order after I set context to 'scheduled'

Hope you can assist.
I am currently trying to conduct one of the most simplest tasks via a user event script - that is to set a new value in the 'discount rate' field on the sales order. My script works fine when testing it on the client, but when the scheduled script is triggered, the field fails to set/update.
The following code is within a 'beforesubmit' operation. Can you spot what I have done wrong?
function beforeSubmit_discountVAT(type){
if(nlapiGetContext().getExecutionContext() !='scheduled')
return;
var getDiscountVal = nlapiGetFieldValue('discountrate');
var correctDiscount = getDiscountVal / 1.2;
nlapiSetFieldValue('discountrate', correctDiscount);
}
In short - All i want to do is deduct the discount value by 20%. Can you use 'nlapiSetFieldValue' when a user event script is triggered from a scheduled script?
Thanks in advance.
AWB
When editing an existing record, nlapiSetFieldValue cannot be used in a Before Load event on fields that are stored with the record. From the function's JSDocs:
Sets the value of a given body field. This API can be used in user event beforeLoad scripts to initialize field on new records or non-stored fields.
nlapiSetFieldValue can thus only be used reliably in Before Load on new records or non-stored fields.
Realizing this is a month old so you've probably found a solution, I would move your code to the Before Submit event. I tested this using a Scheduled Script:
var customer = nlapiLoadRecord('customer', '31294');
nlapiSubmitRecord(customer);
and User Event on the Customer record, Before Submit event:
if (nlapiGetContext().getExecutionContext() === 'scheduled') {
nlapiSetFieldValue('url', 'http://www.google.com/', false);
}
This works as expected for me in a 2013.1 Sandbox environment.
Using nlapiSubmitField in After Submit as mentioned in the other answer is an unnecessarily long operation that will use extra governance units. Not a huge deal if that's the only thing your script is doing, but if you ever expand the script or add looping, it can add up quickly in terms of performance and governance usage.
Also, it may not be necessary, but you should ensure that getDiscountVal is a Number by doing:
var getDiscountVal = parseInt(nlapiGetFieldValue('discountrate'), 10);
If it comes back as a String then your division operation may give a strange result which may also cause nlapiSetFieldValue to fail or set the field to an odd value.
two suggestions
Make sure that your script is being executed by adding a few nlapiLogExecution statements
Instead of doing it in beforesubmit, change this field in aftersubmit function using nlapiSubmitField
"Can you use 'nlapiSetFieldValue' when a user event script is triggered from a scheduled script?"
Yeah Absolutely yes.Context is also correct its scheduled.
Please make sure that you are submitting the record nlapiSubmitRecord(recordObj) at the end.
If you are not comfortable with nlapiSubmitRecord() you can obviously use nlapiSubmitField()
If still you get stuck up then please paste the complete code so that we could assist you.
Cheers!!!

How can I change the TargetControlID of AutoCompleteExtender client side (javascript)?

Normally, I can can set the TargetControlID server side using something like this:
AutoCompleteExtender ace = new AutoCompleteExtender();
ace.ID = "AutoCompleteExtender1";
ace.TargetControlID = "whatever";
I know how to grab the AutoCompleteExtender client side, but I am looking for a method to update the TargetControlID client side too. Any ideas?
Well sadly this is not possible for existing instance of AutoCompleteExtender. There are a few methods that you might be interested in like below
var x = $find("AutocompleteBehaviorID");//find the instance
x.get_completionListElementID();//get the ID of target textbox
x.set_completionListElementID();//set the ID of target textbox has no effect though :(
x._completionListElement();//direct access to DOM element that acts as target
the problem here seems initialized version attaches additional events to target textbox during init phase of the control toolkit( yeah client side too has a init phase). When a initialized version is made to change as the target (as you wanted to do) then these events keypress,blur etc are not added hence you don't see any changes. But if you knew javascript you can do the below to make it work with any textbox.
$create(Behavior,{properties},{events},interfaces,target);
where
Behavior
AjaxControlToolkit.AutoCompleteBehavior
properties
is a javascript object as below (there are more properties but these suffice
{
"completionInterval": 1,
"completionListElementID": "empty panel id",
"completionListItemCssClass": "css class name",
"delimiterCharacters": ";",
"highlightedItemCssClass": "css class name",
"id": "CLIENTSIDEID",
"minimumPrefixLength": 1,
"serviceMethod": "WebMethodName",
"servicePath": "AbsolutePath to asmx file"
}
Events
there are more events available
{
"itemSelected": jsFn,
"populated": jsFn
}
The Target
Target element is the most important. It is this text box that all the events ,bells and whistles attracted to.
$get("ELEMENT ID")
now that is all over , you can initialize a instance of auto complete though javascript all the time. Just make sure the ID already does not exist.
Apparently Microsoft didn't think was important, so there is not a way to do this at this time :)

Categories