Rich-text Reply

Reuse custom event goals

unawaz 04-07-16
Accepted Solution

Reuse custom event goals

It looks the custom javascript for custom event goals always need to added when reusing those goals in some other experiment, right?

I have a couple of custom event goals that have been bind to jQuery ".ajaxCmplete()" But they never trigger untill I add their custom javascript in that experiment. 

Is there any option where I can add these custom javascript lines so that they can be reused? 


Level 2

DavidS 04-08-16

Re: Reuse custom event goals

Hi unawaz,


Thanks for reaching out!


Could you expand a bit more on what you are looking to achieve? 

The Javascript call for a custom event goal looks like this: 

window.optimizely.push(["trackEvent", "eventName"]);

where eventName is the custom event name you are looking to fire. 

Accross experiments, you will have to manually run this code (whether in your variation code, Experiment Javascript or hard-coded on your website). I am not aware of anything allowing you to reuse these lines accross experiments. 


Please let me know if you were looking to do something different and if there is anything else I can do to help. 




unawaz 04-13-16

Re: Reuse custom event goals

I have a couple of custom event goals that need to be triggered in jQuery .ajaxComplete() event function with some more if.else checks. And these (around 30) code lines does not need to change for different experiments.
So, when I see these goals listed in "Use Saved Goals" option in editor/home's "Add Goals" panel, it looks like I can actually Reuse those Custom Goals. That's why I am curious about how this can be achieved instead of copy/paste them again. Does this make sense
If there is no such option, there can be a note displaying "Do not forget to use any previous code or these ('window.optimizely.push(["trackEvent", "eventName"]);') sort of code lines."
Please let me know if the explanation still look confusing.
Level 2
DavidS 04-13-16

Re: Reuse custom event goals



As you mentioned, goals can be used throughout multiple experiments. This is why you see the "Use Saved Goal" feature. You do not need to copy and paste them again. 


As far as the custom event calls, you will still need to make the call when your users trigger the goal. Optimizely will know what experiment to attach them to based on the experiment that your user has been bucketed into. 


Does that answer your concerns? 


Let me know if there is anything else that I can do to help,



JasonDahlin 04-13-16

Re: Reuse custom event goals

[ Edited ]

@unawaz - If your plan supports it, add the code to your Project JavaScript (on you "home" screen, click on "Settings" and see if you are able to add code to "Project JavaScript").  In here you can add the code that listens for ajaxComplete() and pushes the approriate goals when certain things happen.


Alternatively, ask your developers to add it to whatever JS file is common to every page of your site.


(You will still need to add the goal to the experiment, but you won't have to worry about the goals tracking)

--Jason Dahlin
Analytics and Testing Guru Smiley Happy

Experimentation Hero