Skip to content

Commit

Permalink
CID fixes and cookie enhancements
Browse files Browse the repository at this point in the history
- Cookie.js:
  - Set Secure flag when protocol is https
  - Set SameSite option
- Placement.js: Set vendor track param to the server generated CID
- test: Updated for coverage
- Bumped to version v1.15.0
  • Loading branch information
kfitzgerald committed May 29, 2020
1 parent ff8d500 commit 81fe88d
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 56 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

When stuff changes, it's described here.

## 2019-08-19 – v1.13.2
* Fixed CTA color overrides
## 2020-05-28 – v1.15.0
* Use server CIDs for vendor tracking params
* Set SameSite and Secure params on session cookie

## 2020-04-06 – v1.14.0
* Use server generated cids
* Added build task option to skip version bump

## 2019-08-19 – v1.13.2
* Fixed CTA color overrides

## 2019-08-16 – v1.13.0
* Added support for splitfilled widgets
* Added testing option to placements (flags metrics as test metrics)
Expand Down
13 changes: 8 additions & 5 deletions dist/okanjo-bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-js v1.14.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.15.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -323,7 +323,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.14.0",
version: "1.15.0",

/**
* Placeholder
Expand Down Expand Up @@ -1147,7 +1147,10 @@ var okanjo = function (window, document) {
expireDate.setDate(expireDate.getDate() + expireDays);
var expires = expireDays ? " Expires=" + expireDate.toUTCString() + ";" : "";
var path = " Path=/";
var cookieValue = encodeURI(value) + ';' + expires + path;
var secure = window.location.protocol === 'https:' ? ' Secure;' : '';
// const secure = ' Secure;';
var cookieValue = encodeURI(value) + ';' + expires + secure + ' SameSite=None;' + path;
// console.log('setting cookie', cookieName, cookieValue)
document.cookie = cookieName + "=" + cookieValue;
},

Expand Down Expand Up @@ -3501,7 +3504,7 @@ var okanjo = function (window, document) {
var additionalParams = {
ok_cid: clickId
};
if (resource[trackParam]) additionalParams[resource[trackParam]] = (okanjo.metrics.sid || 'unknown') + ':' + clickId;
if (resource[trackParam]) additionalParams[resource[trackParam]] = clickId;

// Update the link with the event data
event.data({ ea: Metrics.Action.click });
Expand Down Expand Up @@ -5003,7 +5006,7 @@ var okanjo = function (window, document) {
return okanjo;
}));

/*! okanjo-js v1.14.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.15.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(okanjo) {(function (window) {

var okanjo = window.okanjo;
Expand Down
12 changes: 6 additions & 6 deletions dist/okanjo-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-bundle.min.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/okanjo-metrics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-metrics.js v1.14.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-metrics.js v1.15.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -319,7 +319,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.14.0",
version: "1.15.0",

/**
* Placeholder
Expand Down Expand Up @@ -1143,7 +1143,10 @@ var okanjo = function (window, document) {
expireDate.setDate(expireDate.getDate() + expireDays);
var expires = expireDays ? " Expires=" + expireDate.toUTCString() + ";" : "";
var path = " Path=/";
var cookieValue = encodeURI(value) + ';' + expires + path;
var secure = window.location.protocol === 'https:' ? ' Secure;' : '';
// const secure = ' Secure;';
var cookieValue = encodeURI(value) + ';' + expires + secure + ' SameSite=None;' + path;
// console.log('setting cookie', cookieName, cookieValue)
document.cookie = cookieName + "=" + cookieValue;
},

Expand Down
6 changes: 3 additions & 3 deletions dist/okanjo-metrics.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-metrics.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/okanjo-templates.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo-templates.min.js.map

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions dist/okanjo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! okanjo-js v1.14.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
/*! okanjo-js v1.15.0 | (c) 2013 Okanjo Partners Inc | https://okanjo.com/ */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
Expand Down Expand Up @@ -323,7 +323,7 @@ var okanjo = function (window, document) {
/**
* Okanjo version
*/
version: "1.14.0",
version: "1.15.0",

/**
* Placeholder
Expand Down Expand Up @@ -1147,7 +1147,10 @@ var okanjo = function (window, document) {
expireDate.setDate(expireDate.getDate() + expireDays);
var expires = expireDays ? " Expires=" + expireDate.toUTCString() + ";" : "";
var path = " Path=/";
var cookieValue = encodeURI(value) + ';' + expires + path;
var secure = window.location.protocol === 'https:' ? ' Secure;' : '';
// const secure = ' Secure;';
var cookieValue = encodeURI(value) + ';' + expires + secure + ' SameSite=None;' + path;
// console.log('setting cookie', cookieName, cookieValue)
document.cookie = cookieName + "=" + cookieValue;
},

Expand Down Expand Up @@ -3501,7 +3504,7 @@ var okanjo = function (window, document) {
var additionalParams = {
ok_cid: clickId
};
if (resource[trackParam]) additionalParams[resource[trackParam]] = (okanjo.metrics.sid || 'unknown') + ':' + clickId;
if (resource[trackParam]) additionalParams[resource[trackParam]] = clickId;

// Update the link with the event data
event.data({ ea: Metrics.Action.click });
Expand Down
10 changes: 5 additions & 5 deletions dist/okanjo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/okanjo.min.js.map

Large diffs are not rendered by default.

63 changes: 50 additions & 13 deletions examples/dfp.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
outside of the iframe (when able to do so) to enable expandable functionality.
-->
<script>
/*! Okanjo Placement Loader v3.0.1 - https://developer.okanjo.com/okanjo-js */
/*! Okanjo Placement Loader v3.1.0 - https://developer.okanjo.com/okanjo-js */
(function (config) {

//noinspection ES6ConvertVarToLetConst
var doc = document,
win = window,
container = doc.getElementById('okanjo-placement-container'),
isTop = win.top === win.self,
isFrameLocated = false;
isFrameLocated = false,
debug = config.debug && function() { console.info.apply(console, arguments); } || function() {};
debug('Okanjo: Initializing...');

try {
// If we're sandboxed to an iframe, try to move the dropzone element to the top-level DOM
if (!isTop) {
debug("Okanjo: Not top frame, locating self...");

// Locate all the iFrames on the main page
//noinspection ES6ConvertVarToLetConst
Expand All @@ -33,6 +36,7 @@
try {
frameDocument = frame.contentDocument || iframes.contentWindow.document; // <-- this can throw
if (frameDocument === document) {
debug("Okanjo: Located self on top: ", frame);
// We found our frame! - that means we're friendly and can promote our content
// Strip our internal ID off before attaching to the main page
container.removeAttribute('id');
Expand All @@ -49,6 +53,7 @@
}
} catch (e) {
// Trying to pull the contentDocument of an unfriendly iframe will throw - so eat the error
debug("Okanjo: Failed to check frame: ", e);
}
}
}
Expand All @@ -60,7 +65,7 @@
// Override if we could not escape and we should have
if (!isTop && !isFrameLocated) {
// Report
console.warn('[Okanjo]', 'Forcing non-expandable functionality.');
console.warn('[Okanjo]', 'Forcing non-expandable functionality. Top=%s, Located=%s', isTop, isFrameLocated);
// Force non-expandable since we failed to escape
config.placement && (config.placement.expandable = false);
}
Expand All @@ -70,44 +75,75 @@
//
// Async load Okanjo-JS
(function (callback) {
// this = top window (if self or friendly) or the current frame if sandboxed
if (this.okanjo) {
// Already loaded
debug('Okanjo: previously loaded');
callback.call(this);
} else {
// The context here should be the window of the target frame
//noinspection ES6ConvertVarToLetConst
var win = this,
document = win.document,
body = document.getElementsByTagName('body')[0],
head = document.head,
script = document.createElement('script'),
scriptLoaded = false;
scriptLoaded = false,
retry = 0,
retryIv;

script.type = 'text/javascript';
script.async = true;
script.setAttribute('crossorigin', "anonymous");
// When the script loads, fire our callback
script.onload = script.onreadystatechange = function () {
if (!scriptLoaded &&
(!this.readyState || this.readyState === 'complete' || this.readyState === 'loaded')) {
scriptLoaded = true;
// Framework loaded, move on to widget initialization
callback.call(win);

script.onload = function (e) {
if (!scriptLoaded) {
debug('Okanjo: SDK loaded, Version=%s, Event=', win.okanjo && win.okanjo.version, e);
if (win.okanjo) {
scriptLoaded = true;
// Framework loaded, move on to widget initialization
callback.call(win);
} else {
debug('Okanjo: SDK did not load, retrying...');
retryIv = setInterval(function() {
// Did it work this time?
if (win.okanjo) {
debug('Okanjo: SDK loaded, Version=%s, Event=', win.okanjo.version, e);
scriptLoaded = true;
clearInterval(retryIv);
// Framework loaded, move on to widget initialization
return callback.call(win);
} else if (++retry > 10) {
clearInterval(retryIv);
console.error('[Okanjo] Failed to load SDK: retries exceeded. Win=', win);
}
}, 100);
}
}
};

script.onerror = function (e) {
console.error('[Okanjo] Failed to load SDK:', e);
};

// Start loading the widget payload
script.src = config.src || "//cdn.okanjo.com/js/latest/okanjo-bundle.min.js";
body.parentNode.insertBefore(script, body);
head.appendChild(script);
}
}).call(win, function () {
// this = top window (if self or friendly) or the current frame if sandboxed

//noinspection ES6ConvertVarToLetConst
var win = this, targets = win.okanjo.qwery('.okanjo-placement:not(.loaded)', container), i = 0;
debug('Okanjo: Loading placements, Found=%d', targets.length);

// Create a bucket for the widget instance, if not already present (e.g. multiple ads on a page)
win.__okanjoPlacements = win.__okanjoPlacements || [];

for (; i < targets.length; i++) {
targets[i].className += ' loaded';
win.__okanjoPlacements.push(new win.okanjo.Placement(targets[i], config.placement));
debug('Okanjo: Loaded placement: ', win.__okanjoPlacements[win.__okanjoPlacements.length-1]);
}
});

Expand All @@ -116,6 +152,7 @@
// key: 'PUT_YOUR_PLACEMENT_KEY_HERE',
// expandable: true,
proxy_url: '%%CLICK_URL_UNESC%%', // (Google DFP macro, change for your ad server)
}
},
debug: true
});
</script>
9 changes: 5 additions & 4 deletions examples/dfp.min.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
outside of the iframe (when able to do so) to enable expandable functionality.
-->
<script>
/*! Okanjo Placement Loader v3.0.1 - https://developer.okanjo.com/okanjo-js */
!function(e){var t=document,n=window,a=t.getElementById("okanjo-placement-container"),o=n.top===n.self,c=!1;try{if(!o)for(var l,r,s=n.top.document.getElementsByTagName("iframe"),i=0;i<s.length;i++){l=s[i];try{if(r=l.contentDocument||s.contentWindow.document,r===document){a.removeAttribute("id"),l.parentNode.appendChild(a),l.style.display="none",t=n.top.document,n=n.top,c=!0;break}}catch(d){}}}catch(d){console.warn("[Okanjo]","Failed to locating parent frame.",d)}o||c||(console.warn("[Okanjo]","Forcing non-expandable functionality."),e.placement&&(e.placement.expandable=!1)),function(t){if(this.okanjo)t.call(this);else{var n=this,a=n.document,o=a.getElementsByTagName("body")[0],c=a.createElement("script"),l=!1;c.type="text/javascript",c.async=!0,c.setAttribute("crossorigin","anonymous"),c.onload=c.onreadystatechange=function(){l||this.readyState&&"complete"!==this.readyState&&"loaded"!==this.readyState||(l=!0,t.call(n))},c.src=e.src||"//cdn.okanjo.com/js/latest/okanjo-bundle.min.js",o.parentNode.insertBefore(c,o)}}.call(n,function(){var t=this,n=t.okanjo.qwery(".okanjo-placement:not(.loaded)",a),o=0;for(t.__okanjoPlacements=t.__okanjoPlacements||[];o<n.length;o++)n[o].className+=" loaded",t.__okanjoPlacements.push(new t.okanjo.Placement(n[o],e.placement))})
}({
/*! Okanjo Placement Loader v3.1.0 - https://developer.okanjo.com/okanjo-js */
(function(i){var e=document,n=window,a=e.getElementById("okanjo-placement-container"),o=n.top===n.self,t=false,s=i.debug&&function(){console.info.apply(console,arguments)}||function(){};s("Okanjo: Initializing...");try{if(!o){s("Okanjo: Not top frame, locating self...");var l=n.top.document.getElementsByTagName("iframe"),c=0,r,d;for(;c<l.length;c++){r=l[c];try{d=r.contentDocument||l.contentWindow.document;if(d===document){s("Okanjo: Located self on top: ",r);a.removeAttribute("id");r.parentNode.appendChild(a);r.style.display="none";e=n.top.document;n=n.top;t=true;break}}catch(j){s("Okanjo: Failed to check frame: ",j)}}}}catch(j){console.warn("[Okanjo]","Failed to locating parent frame.",j)}if(!o&&!t){console.warn("[Okanjo]","Forcing non-expandable functionality. Top=%s, Located=%s",o,t);i.placement&&(i.placement.expandable=false)}(function(n){if(this.okanjo){s("Okanjo: previously loaded");n.call(this)}else{var o=this,e=o.document,a=e.head,t=e.createElement("script"),l=false,c=0,r;t.type="text/javascript";t.async=true;t.setAttribute("crossorigin","anonymous");t.onload=function(e){if(!l){s("Okanjo: SDK loaded, Version=%s, Event=",o.okanjo&&o.okanjo.version,e);if(o.okanjo){l=true;n.call(o)}else{s("Okanjo: SDK did not load, retrying...");r=setInterval(function(){if(o.okanjo){s("Okanjo: SDK loaded, Version=%s, Event=",o.okanjo.version,e);l=true;clearInterval(r);return n.call(o)}else if(++c>10){clearInterval(r);console.error("[Okanjo] Failed to load SDK: retries exceeded. Win=",o)}},100)}}};t.onerror=function(e){console.error("[Okanjo] Failed to load SDK:",e)};t.src=i.src||"//cdn.okanjo.com/js/latest/okanjo-bundle.min.js";a.appendChild(t)}}).call(n,function(){var e=this,n=e.okanjo.qwery(".okanjo-placement:not(.loaded)",a),o=0;s("Okanjo: Loading placements, Found=%d",n.length);e.__okanjoPlacements=e.__okanjoPlacements||[];for(;o<n.length;o++){n[o].className+=" loaded";e.__okanjoPlacements.push(new e.okanjo.Placement(n[o],i.placement));s("Okanjo: Loaded placement: ",e.__okanjoPlacements[e.__okanjoPlacements.length-1])}})
})({
placement: {
// key: 'PUT_YOUR_PLACEMENT_KEY_HERE',
// expandable: true,
proxy_url: '%%CLICK_URL_UNESC%%', // (Google DFP macro, change for your ad server)
}
},
// debug: true
});
</script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "okanjo-js",
"homepage": "https://okanjo.com/",
"version": "1.14.0",
"version": "1.15.0",
"description": "Okanjo JavaScript Widget Framework",
"main": "index.js",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion src/Cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
expireDate.setDate(expireDate.getDate() + expireDays);
const expires = expireDays ? " Expires=" + expireDate.toUTCString() + ";" : "";
const path = " Path=/";
const cookieValue = `${encodeURI(value)};${expires}${path}`;
const secure = window.location.protocol === 'https:' ? ' Secure;' : '';
// const secure = ' Secure;';
const cookieValue = `${encodeURI(value)};${expires}${secure} SameSite=None;${path}`;
// console.log('setting cookie', cookieName, cookieValue)
document.cookie = cookieName + "=" + cookieValue;
},

Expand Down
2 changes: 1 addition & 1 deletion src/Placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
const additionalParams = {
ok_cid: clickId
};
if (resource[trackParam]) additionalParams[resource[trackParam]] = (okanjo.metrics.sid || 'unknown') + ':' + clickId;
if (resource[trackParam]) additionalParams[resource[trackParam]] = clickId;

// Update the link with the event data
event.data({ ea: Metrics.Action.click });
Expand Down
23 changes: 23 additions & 0 deletions test/cookie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,27 @@ describe('Cookie', () => {

});

describe('https', () => {

it('should set https flag', () => {

// Fudge the UA
TestUtil.cleanEnvironment();
TestUtil.setupEnvironment({
url: "https://okanjo.com/test?query=1#hash=2&nope"
});
should(window.okanjo).be.exactly(undefined);
TestUtil.reloadOkanjo();
TestUtil.reloadCookie();
should(window.okanjo).be.ok();

const key = 'unit_test2', value = 'was here';
window.okanjo.util.cookie.set(key, value, 1);
let res = window.okanjo.util.cookie.get(key);
res.should.be.exactly(value);

});

});

});
2 changes: 1 addition & 1 deletion test/placement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ describe('Placements', () => {
args.u.should.be.ok().and.startWith('http://proxy.test?u=');

let targetUrl = Qs.parse(Url.parse(args.u).query).u;
Qs.parse(Url.parse(targetUrl).query).afftrack.should.match(/unknown:.+/);
Qs.parse(Url.parse(targetUrl).query).afftrack.should.match(/SSCLK.+/);

done();
});
Expand Down

0 comments on commit 81fe88d

Please sign in to comment.