Skip to content

Commit

Permalink
added var args support in page
Browse files Browse the repository at this point in the history
  • Loading branch information
prabrisha-rudder authored and sayan-rudder committed Sep 30, 2019
1 parent bb0254c commit d7ff6cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
5 changes: 3 additions & 2 deletions rudder-client-javascript/test/dist/test_browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ <h1>Page Loaded</h1>
//analytics.page();
analytics.page("Dashboard", {
"title":"abc",
"url":"http://abc.com"
});
"url":"http://abc.com",
"path":"/abc"
},()=>{console.log("in callback html")});
</script>
<script src="browser.js"></script>

Expand Down
48 changes: 29 additions & 19 deletions rudder-client-javascript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,34 @@ class test {
init.call(this, this.clientIntegrations, this.configArray);
}

page() {
console.log("type=== " + typeof arguments);

var args = Array.from(arguments);
console.log("args ", args);
page(category, name, properties, options, callback) {

if (typeof(options) == "function") (callback = options), (options = null);
if (typeof(properties) == "function") (callback = properties), (options = properties = null);
if (typeof(name) == "function") (callback = name), (options = properties = name = null);
if (typeof(category) === 'object')
(options = name), (properties = category), (name = category = null);
if (typeof(name) === 'object')
(options = properties), (properties = name), (name = null);
if (typeof(category) === 'string' && typeof(name) !== 'string')
(name = category), (category = null);

var rudderElement = new RudderElementBuilder().build();
//console.log(typeof(arguments[0]))
if(arguments.length > 0){
//console.log("arg length ",arguments.length)
let methodArguments = arguments//arguments[0]
if(methodArguments[0]){
console.log("arg0 ", methodArguments[0])
rudderElement['rl_message']['rl_name'] = methodArguments[0]//JSON.parse(arguments[1]);
}
//console.log("arg1 ",methodArguments[1])
if(methodArguments[1]){
console.log(JSON.parse(JSON.stringify(methodArguments[1])))
rudderElement['rl_message']['rl_properties'] = methodArguments[1]//JSON.parse(arguments[1]);
}

//console.log("arg length ",arguments.length)
let methodArguments = arguments//arguments[0]
if(name){
console.log("name ", name)
rudderElement['rl_message']['rl_name'] = name//JSON.parse(arguments[1]);
}
if(category){
if(!properties){
properties = {}
}
properties['category'] = category
}
if(properties){
console.log(JSON.parse(JSON.stringify(properties)))
rudderElement['rl_message']['rl_properties'] = properties//JSON.parse(arguments[1]);
}
console.log(JSON.stringify(rudderElement));

Expand Down Expand Up @@ -162,6 +169,9 @@ class test {
flush.call(rudderElement)

console.log("page called " + this.prop1);
if(callback){
callback()
}
}

track() {
Expand Down

0 comments on commit d7ff6cc

Please sign in to comment.