Skip to content

Commit

Permalink
added var args support in track
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 9688354 commit 8a1efe7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
15 changes: 11 additions & 4 deletions rudder-client-javascript/test/dist/test_browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ <h1>Page Loaded</h1>
analytics = window.analytics = [];
analytics.page = function() {
console.log(...arguments)
//analytics.push(["page", arguments[0], arguments[1]]);
var name = arguments[0]
analytics.push(["page", ...arguments]);
};
analytics.track = function() {
analytics.push(["track", ...arguments]);
};

analytics.load = function(writeKey) {
analytics.push(["load", writeKey]);
Expand All @@ -23,7 +24,12 @@ <h1>Page Loaded</h1>
"title":"abc",
"url":"http://abc.com",
"path":"/abc"
},()=>{console.log("in callback html")});
},()=>{console.log("in page callback html")});
analytics.track('Article Started', {
title: 'How to Create a Tracking Plan',
course: 'Intro to Analytics',
revenue: 10
});
</script>
<script src="browser.js"></script>

Expand All @@ -37,7 +43,8 @@ <h1>Page Loaded</h1>
analytics.track('Article Completed', {
title: 'How to Create a Tracking Plan',
course: 'Intro to Analytics',
});
revenue: 20
}, ()=>{console.log("in track callback html")});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions rudder-client-javascript/test/integrations/HubSpot/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class HubSpot {
let _hsq = (window._hsq = window._hsq || []);
//console.log("path: " + rudderElement.rl_message.rl_properties.path);
//_hsq.push(["setPath", rudderElement.rl_message.rl_properties.path]);
_hsq.push(["identify",{
email: "testtrackpage@email.com"
}]);
if(rudderElement.rl_message.rl_properties && rudderElement.rl_message.rl_properties.path){
_hsq.push(["setPath", rudderElement.rl_message.rl_properties.path]);
}
_hsq.push(["trackPageView"]);
}

Expand Down
35 changes: 33 additions & 2 deletions rudder-client-javascript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,39 @@ class test {
}
}

track() {
console.log("track called " + this.prop2);
track(event, properties, options, callback) {
if (typeof(options) == "function") (callback = options), (options = null);
if (typeof(properties) == "function")
(callback = properties), (options = null), (properties = null);
var rudderElement = new RudderElementBuilder().build();
if(event){
rudderElement.setEventName(event)
}
if(properties){
rudderElement.setProperty(properties)
}
console.log(JSON.stringify(rudderElement));

//try to first send to all integrations, if list populated from BE
if(this.clientIntegrationObjects){
this.clientIntegrationObjects.forEach(obj => {
console.log("called in normal flow");
obj.track(rudderElement)
});
}
if (!this.clientIntegrationObjects) {
console.log("pushing in replay queue");
//new event processing after analytics initialized but integrations not fetched from BE
this.toBeProcessedByIntegrationArray.push(["track", rudderElement]);
}

// self analytics process
flush.call(rudderElement)

console.log("track is called " + this.prop2);
if(callback){
callback()
}
}

load(writeKey) {
Expand Down

0 comments on commit 8a1efe7

Please sign in to comment.