Skip to content

Commit 30cd992

Browse files
mericssonskarim
andauthored
[Hindsight / Rockerbox] Add Custom Domain Option (#525)
Co-authored-by: Sameen Karim <sameenkarim@gmail.com>
1 parent fa04252 commit 30cd992

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

integrations/hindsight/HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
1.2.0 / 2020-12-15
3+
=============
4+
5+
* Adding custom_tracking_domain option
6+
27
1.1.0 / 2018-10-10
38
=============
49

integrations/hindsight/lib/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var integration = require('@segment/analytics.js-integration');
4-
var useHttps = require('use-https');
54
var is = require('is');
65
var each = require('@ndhoule/each');
76

@@ -13,8 +12,9 @@ var each = require('@ndhoule/each');
1312
var Hindsight = (module.exports = integration('Hindsight')
1413
.global('RB')
1514
.option('pixel_code', '')
16-
.tag('http', '<script src="http://getrockerbox.com/assets/xyz.js">')
17-
.tag('https', '<script src="https://getrockerbox.com/assets/xyz.js">'));
15+
.option('customTrackingDomain', '')
16+
.option('enableCookieSync', true)
17+
.tag('<script src="https://{{ host }}/assets/{{ lib }}.js">'));
1818

1919
/**
2020
* Initialize
@@ -31,9 +31,18 @@ Hindsight.prototype.initialize = function() {
3131
};
3232
window.RB.source = this.options.pixel_code;
3333

34-
var protocol = useHttps() ? 'https' : 'http';
35-
36-
this.load(protocol, this.ready);
34+
var hasCustomDomain = !!this.options.customTrackingDomain;
35+
var enableCookieSync = this.options.enableCookieSync;
36+
var scriptHost = hasCustomDomain
37+
? this.options.customTrackingDomain
38+
: 'getrockerbox.com';
39+
var scriptLib = hasCustomDomain && enableCookieSync ? 'wxyz.rb' : 'wxyz.v2';
40+
var tagParams = {
41+
host: scriptHost,
42+
lib: scriptLib
43+
};
44+
45+
this.load(tagParams, this.ready);
3746
};
3847

3948
/**
@@ -77,7 +86,8 @@ Hindsight.prototype.identify = function(identify) {
7786
function format(props) {
7887
var ret = {};
7988
each(function(value, key) {
80-
return (ret[key] = is.object(value) ? window.JSON.stringify(value) : value);
89+
ret[key] = is.object(value) ? window.JSON.stringify(value) : value;
90+
return ret[key];
8191
}, props);
8292

8393
return ret;

integrations/hindsight/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-hindsight",
33
"description": "The Hindsight analytics.js integration.",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",
@@ -25,8 +25,7 @@
2525
"dependencies": {
2626
"@ndhoule/each": "^2.0.1",
2727
"@segment/analytics.js-integration": "^3.2.0",
28-
"is": "^3.2.1",
29-
"use-https": "^0.1.1"
28+
"is": "^3.2.1"
3029
},
3130
"devDependencies": {
3231
"@segment/analytics.js-core": "^3.8.2",

integrations/hindsight/test/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('Hindsight', function() {
1010
var hindsight;
1111
var options = {
1212
pixel_code:
13-
'cHVzaG1haWx8NDQ2MDM5OHw0NDYwMzkyOjY1NzU2OXw0NDYwMzkzOjY1NzU2OHw0NDYwMzk5'
13+
'cHVzaG1haWx8NDQ2MDM5OHw0NDYwMzkyOjY1NzU2OXw0NDYwMzkzOjY1NzU2OHw0NDYwMzk5',
14+
customTrackingDomain: 'metrics.getrockerbox.com'
1415
};
1516

1617
beforeEach(function() {

0 commit comments

Comments
 (0)