Skip to content

Commit

Permalink
V2.0.0 (#6)
Browse files Browse the repository at this point in the history
* Reworked to decouple scroll observing from GA tracking, added support for nested scroll areas.
  • Loading branch information
DanWilkerson authored Sep 11, 2017
1 parent 5ec504e commit 7e3870e
Show file tree
Hide file tree
Showing 13 changed files with 1,963 additions and 1,546 deletions.
57 changes: 19 additions & 38 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* @TODO add task for updating container
*/
var fs = require('fs');
var jsBeautify = require('js-beautify').js_beautify;

Expand All @@ -15,7 +18,6 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
// files: ['./src/*.js'],
ignore_warning: {
options: {
'-W030': true,
Expand All @@ -26,35 +28,27 @@ module.exports = function(grunt) {
},
uglify: {
options: {
footer: footer
footer: '\r\n' + footer
},
build: {
src: './src/lunametrics-scroll-tracking.gtm.js',
dest: './lunametrics-scroll-tracking.gtm.min.js'
src: './src/scroll-tracker.js',
dest: './scroll-tracker.min.js'
}
},
fixConfig: {
appendFooter: {
options: {
build: {
src: './lunametrics-scroll-tracking.gtm.min.js',
dest: './lunametrics-scroll-tracking.gtm.min.js'
}
}
},
prependFooter: {
options: {
build: {
src: './src/lunametrics-scroll-tracking.gtm.js',
dest: './lunametrics-scroll-tracking.gtm.js'
src: './src/scroll-tracker.js',
dest: './scroll-tracker.js'
},
footer: footer
}
},
updateContainer: {
options: {
build: {
src: './lunametrics-scroll-tracking.gtm.js',
dest: './luna-scroll-tracking.json'
src: './scroll-tracker.js',
dest: './luna-gtm-scroll-tracker.json'
}
}
}
Expand All @@ -63,32 +57,19 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.registerTask('fixConfig', ['Reformat config argument for readability'], function() {
grunt.registerTask('appendFooter', ['append credits to footer'], function() {

var options = this.options();
var data = fs.readFileSync(options.build.src, 'utf-8');
var minifiedConfig = data.split('/*')[0].match(/\(.*?\)/g).pop();
var config = minifiedConfig.replace(/!0/g, 'true').replace(/!1/g, 'false');
var beautifiedConfig = jsBeautify(config);
var data = data.replace(minifiedConfig, '\n' + beautifiedConfig);
fs.writeFileSync(options.build.dest, data);
console.log('Appended properly formatted config to end of minified script');

});

grunt.registerTask('prependFooter', ['Prepend credits to footer'], function() {

var options = this.options();
var data = fs.readFileSync(options.build.src, 'utf-8');
fs.writeFileSync(options.build.dest, data + options.footer);
console.log('Prepended footer to unminifed script');
console.log('appended footer to unminifed script');

});

grunt.registerTask('updateContainer', ['Updating container import file'], function() {
/*grunt.registerTask('updateContainer', ['Updating container import file'], function() {
var options = this.options();
var oldContainer = require(options.build.dest);
var oldContainer = require(options.build.dest);
var newScript = fs.readFileSync(options.build.src, 'utf-8');
var oldTag,
oldParameter,
Expand All @@ -114,15 +95,15 @@ module.exports = function(grunt) {
}
}
oldContainer.containerVersion.tag[oldTag].parameter[oldParameter].value = '<script type="text/javascript" id="gtm-scroll-tracking">\n' +
newScript +
'\n</script>';
fs.writeFileSync(options.build.dest, jsBeautify(JSON.stringify(oldContainer)));
});
});*/

grunt.registerTask('default', ['jshint', 'prependFooter', 'uglify', 'fixConfig', 'updateContainer']);
grunt.registerTask('default', ['jshint', 'appendFooter', 'uglify', /*'updateContainer'*/]);

};
2 changes: 1 addition & 1 deletion LICENSE.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 LunaMetrics, LLC
Copyright (c) 2017 LunaMetrics, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
20 changes: 20 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function(config) {
'use strict';

config.set({

basePath: './',

frameworks: ["jasmine"],

files: [
'src/scroll-tracker.js',
'test/**/*.spec.js'
],

autoWatch: true,

browsers: ['Chrome']

});
};
410 changes: 235 additions & 175 deletions luna-scroll-tracking.json

Large diffs are not rendered by default.

Loading

0 comments on commit 7e3870e

Please sign in to comment.