Skip to content

Commit

Permalink
Allow providing custom view segments
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Mar 15, 2020
1 parent 4bd50fe commit f82dbb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
29 changes: 15 additions & 14 deletions lib/countly-bulk-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,17 @@ function CountlyBulkUser(conf){
/**
* Report user accessing specific view in your application
* @param {string} view_name - name of the view or any other view identifier
* @param {string} platform - on which platforms/os did user access this view
* @param {number} timestamp - when user accessed the view
* @param {number} duration - how much did user spent on this view
* @param {boolean=} landing - true if user started using your app with this view
* @param {boolean=} exit - true if user exited your app after this view
* @param {boolean=} bounce - true if user bounced having only one view and without much interaction with the app
* @param {object=} viewSegments - optional key value object with segments to report with the view
* @param {string} viewSegments.platform - on which platforms/os did user access this view
* @param {boolean=} viewSegments.landing - true if user started using your app with this view
* @param {boolean=} viewSegments.exit - true if user exited your app after this view
* @param {boolean=} viewSegments.bounce - true if user bounced having only one view and without much interaction with the app
* @param {boolean=} viewSegments.{any} - provide any other key value pairs to store with view
* @returns {module:lib/countly-bulk-user} instance
**/
this.report_view = function(view_name, platform, timestamp, duration, landing, exit, bounce){
this.report_view = function(view_name, timestamp, duration, viewSegments){
if(this.check_consent("views")){
var event = {
"key": "[CLY]_view",
Expand All @@ -370,18 +372,17 @@ function CountlyBulkUser(conf){
"segmentation": {
"name": view_name,
"visit":1,
"segment":platform
}
};
if(landing){
event.segmentation.start = 1;
}
if(exit){
event.segmentation.exit = 1;
}
if(bounce){
event.segmentation.bounce = 1;

if (viewSegments) {
for (var key in viewSegments) {
if (typeof event.segmentation[key] === "undefined") {
event.segmentation[key] = viewSegments[key];
}
}
}

var query = prepareQuery({events:[event]});
if(timestamp){
query.timestamp = timestamp;
Expand Down
16 changes: 13 additions & 3 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,9 @@ Countly.Bulk = Bulk;
/**
* Track which parts of application user visits
* @param {string=} name - optional name of the view
* @param {object=} viewSegments - optional key value object with segments to report with the view
**/
Countly.track_view = function(name){
Countly.track_view = function(name, viewSegments){
reportViewDuration();
if(name){
lastView = name;
Expand All @@ -875,6 +876,14 @@ Countly.Bulk = Bulk;
"segment":platform
};

if (viewSegments) {
for (var key in viewSegments) {
if (typeof segments[key] === "undefined") {
segments[key] = viewSegments[key];
}
}
}

//track pageview
if(Countly.check_consent("views")){
add_cly_events({
Expand All @@ -891,9 +900,10 @@ Countly.Bulk = Bulk;
/**
* Track which parts of application user visits. Alias of {@link track_view} method for compatability with Web SDK
* @param {string=} name - optional name of the view
* @param {object=} viewSegments - optional key value object with segments to report with the view
**/
Countly.track_pageview = function(name){
Countly.track_view(name);
Countly.track_pageview = function(name, viewSegments){
Countly.track_view(name, viewSegments);
};

/**
Expand Down

0 comments on commit f82dbb6

Please sign in to comment.