Skip to content

Commit

Permalink
Added 3 day cache busting for loading snippet js script
Browse files Browse the repository at this point in the history
  • Loading branch information
stuyam committed Apr 13, 2016
1 parent df6c2af commit 7ada033
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions openpixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ var Controller = {
// set guid for user for 2 years
Cookie.set('uid', guid(), 2 * 365 * 24 * 60);
}
} else if (value == 'pageview') {
if (!Config.pageViewOnce && !Cookie.exists('pageview')) {
} else if (value == 'pageload') {
if (!Config.pageViewOnce && !Cookie.exists('pageload')) {
Config.pageViewOnce = true;
// set 10 minutes page view cookie
Cookie.set('pageview', 'true', 10, window.location.pathname);
Cookie.set('pageload', 'true', 10, window.location.pathname);
new Pixel(value, pixelFunc.t);
}
} else if (event == 'event' && value != 'pageclose') {
Expand Down
2 changes: 1 addition & 1 deletion openpixel.min.js

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

15 changes: 8 additions & 7 deletions snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

<!-- Start Open Pixel Minified -->
<script>
!function(a,b,c,d,e,f,g,h){a[e]||(f=a[e]=function(){f.process?f.process.apply(f,arguments):f.queue.push(arguments)},f.queue=[],f.t=1*new Date,g=b.createElement(c),g.async=1,g.src=d,h=b.getElementsByTagName(c)[0],h.parentNode.insertBefore(g,h))}(window,document,"script","http://serveme:2000/openpixel.js","opix"),
!function(a,b,c,d,e,f,g,h,i){a[e]||(g=a[e]=function(){g.process?g.process.apply(g,arguments):g.queue.push(arguments)},g.queue=[],g.t=1*new Date,h=b.createElement(c),h.async=1,h.src=d+"?v="+Math.ceil(new Date/f)*f,i=b.getElementsByTagName(c)[0],i.parentNode.insertBefore(h,i))}(window,document,"script","//pixel.dockwa.com/v1/openpixel.js","opix",259200);

opix("init","1234567890");
opix("event","pageview");
opix("event","pageload");
</script>
<!-- End Open Pixel Minified -->


<!-- Start Open Pixel Unminified -->
<script>
!function(window, document, script, http, opix, one, two, three) {
!function(window, document, script, http, opix, cacheTime, one, two, three) {

// return if the setup has already occurred
// this is to prevent double loading openpixel.js if someone accidently had this more than once on a page
Expand All @@ -33,19 +34,19 @@
two = document.createElement(script);
// set the script tag to run async
two.async = 1;
// set the source of the script tag
two.src = http;
// set the source of the script tag and cache bust every 3 days
two.src = http + '?v=' + (Math.ceil(new Date()/cacheTime)*cacheTime);

// get the first <script> that occures in the document
// if this block is the only <script> tag on the page it will get this block
three = document.getElementsByTagName(script)[0];
// insert the newly created script tag above the first <script> tag in the document
// this ensures openpixel.js is loaded asynchronously
three.parentNode.insertBefore(two, three)
}(window, document, 'script', '//pixel.dockwa.com/v1/openpixel.js', 'opix');
}(window, document, 'script', '//pixel.dockwa.com/v1/openpixel.js', 'opix', 3*24*60*60);

// initialize with the ID of the what you are trying to
opix('init', '1234567890');
opix('event', 'pageview');
opix('event', 'pageload');
</script>
<!-- End Open Pixel Unminified -->
6 changes: 3 additions & 3 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var Controller = {
// set guid for user for 2 years
Cookie.set('uid', guid(), 2*365*24*60);
}
} else if(value == 'pageview'){
if(!Config.pageViewOnce && !Cookie.exists('pageview')){
} else if(value == 'pageload'){
if(!Config.pageViewOnce && !Cookie.exists('pageload')){
Config.pageViewOnce = true;
// set 10 minutes page view cookie
Cookie.set('pageview', 'true', 10, window.location.pathname);
Cookie.set('pageload', 'true', 10, window.location.pathname);
new Pixel(value, pixelFunc.t);
}
} else if(event == 'event' && value != 'pageclose'){
Expand Down

0 comments on commit 7ada033

Please sign in to comment.