Skip to content

Commit

Permalink
integrated identify call
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 8a1efe7 commit e6ca854
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
11 changes: 10 additions & 1 deletion rudder-client-javascript/test/dist/test_browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ <h1>Page Loaded</h1>
analytics.track = function() {
analytics.push(["track", ...arguments]);
};
analytics.identify = function() {
analytics.push(["identify", ...arguments]);
};

analytics.load = function(writeKey) {
analytics.push(["load", writeKey]);
};

analytics.load("1QbNPCBQp2RFWolFj2ZhXi2ER6a");
analytics.page("Wishlist");
//analytics.page("Wishlist");
//analytics.page();
analytics.identify({
name: "Tintin",
city: "Brussels",
country: "Belgium",
email: "tintin@herge.com"
}, ()=>{console.log("in identify callback html")});
analytics.page("Dashboard", {
"title":"abc",
"url":"http://abc.com",
Expand Down
4 changes: 2 additions & 2 deletions rudder-client-javascript/test/integrations/HubSpot/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ 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",{
/* _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]);
}
Expand Down
62 changes: 57 additions & 5 deletions rudder-client-javascript/test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { getJSONTrimmed } from "../utils/utils";
import { getJSONTrimmed, generateUUID } from "../utils/utils";
import { CONFIG_URL, BASE_URL} from "../utils/constants";
import { integrations } from "./integrations";
import { RudderElementBuilder } from "../utils/RudderElementBuilder";
import { getCurrentTimeFormatted } from "../utils/utils";
import { replacer } from "../utils/utils";
import { RudderPayload } from "../utils/RudderPayload";
import { RudderTraits } from "../utils/RudderTraits";

function init(intgArray, configArray) {
console.log("supported intgs ", integrations);
Expand Down Expand Up @@ -86,6 +87,7 @@ class test {
this.clientIntegrationObjects = undefined;
this.toBeProcessedArray = [];
this.toBeProcessedByIntegrationArray = [];
this.userId = undefined;
}

processResponse(status, response) {
Expand Down Expand Up @@ -143,6 +145,9 @@ class test {
console.log(JSON.parse(JSON.stringify(properties)))
rudderElement['rl_message']['rl_properties'] = properties//JSON.parse(arguments[1]);
}
if(this.userId){
rudderElement['rl_message']['rl_anonymous_id'] = rudderElement['rl_message']['rl_user_id'] = this.userId;
}
console.log(JSON.stringify(rudderElement));

//try to first send to all integrations, if list populated from BE
Expand Down Expand Up @@ -188,6 +193,9 @@ class test {
if(properties){
rudderElement.setProperty(properties)
}
if(this.userId){
rudderElement['rl_message']['rl_anonymous_id'] = rudderElement['rl_message']['rl_user_id'] = this.userId;
}
console.log(JSON.stringify(rudderElement));

//try to first send to all integrations, if list populated from BE
Expand All @@ -212,6 +220,50 @@ class test {
}
}

identify(userId, traits, options, callback){
if (typeof(options) == "function") (callback = options), (options = null);
if (typeof(traits) == "function") (callback = traits), (options = null), (traits = null);
if (typeof(userId) == "object") (options = traits), (traits = userId), (userId = generateUUID());

this.userId = userId;
var rudderElement = new RudderElementBuilder().build();
var rudderTraits = new RudderTraits();
console.log(traits)
if(traits){
for (let k in traits) {
if (!!Object.getOwnPropertyDescriptor(traits, k) && traits[k]) {
rudderTraits[k] = traits[k]
}
}
}
rudderElement['rl_message']['rl_context']['rl_traits'] = rudderTraits;
rudderElement['rl_message']['rl_anonymous_id'] = rudderElement['rl_message']['rl_user_id'] = this.userId;

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.identify(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(["identify", rudderElement]);
}

// self analytics process
flush.call(rudderElement)

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

}

load(writeKey) {
console.log("inside load " + this.prop1);
getJSONTrimmed(
Expand All @@ -225,7 +277,7 @@ class test {
let instance = new test();

if (process.browser) {
console.log("is present? " + !!window.analytics);
//console.log("is present? " + !!window.analytics);
let eventsPushedAlready =
!!window.analytics && window.analytics.push == Array.prototype.push;

Expand All @@ -240,14 +292,14 @@ if (process.browser) {
instance.toBeProcessedArray.push(window.analytics[i]);
}

console.log("queued " + instance.toBeProcessedArray.length);
//console.log("queued " + instance.toBeProcessedArray.length);

for (let i = 0; i < instance.toBeProcessedArray.length; i++) {
let event = [...instance.toBeProcessedArray[i]];
console.log("replay event " + event);
//console.log("replay event " + event);
let method = event[0];
event.shift();
console.log("replay event modified " + event);
//console.log("replay event modified " + event);
instance[method](...event);
}
instance.toBeProcessedArray = [];
Expand Down

0 comments on commit e6ca854

Please sign in to comment.