layer-handler 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +17 -0
- data/LICENSE +21 -0
- data/README.md +119 -0
- data/Rakefile +1 -0
- data/bin/test +9 -0
- data/dist/layer-handler.min.js +1 -0
- data/gruntfile.js +52 -0
- data/layer-handler.gemspec +21 -0
- data/lib/generators/layer/handler/install_generator.rb +14 -0
- data/lib/generators/layer/handler/templates/layer_handler_initializer.rb +4 -0
- data/lib/layer/handler.rb +31 -0
- data/lib/layer/handler/rails/view_helpers.rb +15 -0
- data/lib/layer/handler/version.rb +5 -0
- data/lib/tasks/layer/handler_tasks.rake +4 -0
- data/package.json +25 -0
- data/src/layer-handler.js +84 -0
- data/vendor/assets/javascripts/layer-handler/layer-handler.min.js +1 -0
- data/vendor/assets/javascripts/layer_handler.js +13 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d02c8c0aa9fe11817dd6795199396c1d58649188
|
4
|
+
data.tar.gz: 93f672aa8198d8326b1d0f7bf19afd6942aa2132
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d57837d71a721b43464859147b69253b62a614ad466bc97dcc63e65731715a3268b7e7b080b377a5322d8c48b6e9195579abcaae3ef71501e9fd99ca320ef891
|
7
|
+
data.tar.gz: d14064e3d46048f4b09b45511f04b313b3fe7cfa0b7a0991e42dd33db3e3dc9d612aab58046c93e116af03498eb832bf0d048b6a284275141e7e874c2711e2ce
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/node_modules
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
0.1.0 / 2016-02-03
|
2
|
+
==================
|
3
|
+
* Added more events to handle: contextmenu, dblclick, mousedown, mouseenter, mouseleave, mousemove, mouseover, mouseout, mouseup, keydown, keypress, keyup, abort, beforeunload, error, hashchange, load, pageshow, pagehide, resize, scroll, unload, blur, change, focus, focusin, focusout, input, invalid, reset, search, select, submit.
|
4
|
+
|
5
|
+
0.0.1 / 2016-02-01
|
6
|
+
==================
|
7
|
+
* First version. Only is handled click event.
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in layer-handler.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use a debugger
|
14
|
+
# gem 'byebug', group: [:development, :test]
|
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ivan Gonzalez Saiz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# LayerHandler
|
2
|
+
|
3
|
+
LayerHandler is a (work in progress) simple JS library to handle Google Tag Manager easily.
|
4
|
+
|
5
|
+
It initializes the **GTM dataLayer** object, appends to your **HTML** body tag the **GTM** script code, and binds the specific events to all the **HTML** tags that have the **data-gtm-*** data attribute, pushing automatically the content of this data attribute to the **dataLayer** object. And all in one and little javascript library :)
|
6
|
+
|
7
|
+
## Table of contents
|
8
|
+
|
9
|
+
* [Usage](#usage)
|
10
|
+
* [Bind Event](#bind-event)
|
11
|
+
* [Rails Gem](#rails-gem)
|
12
|
+
* [TODO](#todo)
|
13
|
+
* [Contributing](#contributing)
|
14
|
+
* [License](#license)
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Copy the `dist/layer-handler.min.js` file into your JS assets folder.
|
19
|
+
|
20
|
+
The library works with one basic special data attribute: **data-gtm-**. It search through all the **HTML** elements of your page to find this attribute, and binds the events and push the data you want.
|
21
|
+
|
22
|
+
Fill the **data-gtm-page** attribute on the **body** tag to initialize the **dataLayer** like this:
|
23
|
+
|
24
|
+
```
|
25
|
+
<body data-gtm-page='{"someKeyOnBody": "hello", "otherKeyOnBody": "bye"}'> </body>
|
26
|
+
```
|
27
|
+
|
28
|
+
This will initialize your **dataLayer** object with this info:
|
29
|
+
|
30
|
+
```
|
31
|
+
{"someKeyOnBody": "hello", "otherKeyOnBody": "bye"}
|
32
|
+
```
|
33
|
+
|
34
|
+
And in all the **HTML** tags you want to track, like this:
|
35
|
+
|
36
|
+
```
|
37
|
+
<a href="#" data-gtm-click='{"someKey": "hello", "otherKey": "bye"}'>Hello!</a>
|
38
|
+
```
|
39
|
+
|
40
|
+
Then simply add the **js** file to your page, and execute the **init** method passing your **GTM-ID** like this:
|
41
|
+
|
42
|
+
```
|
43
|
+
LayerHandler.init("YOUR_GTM_ID_HERE");
|
44
|
+
```
|
45
|
+
|
46
|
+
> ALERT! It's important to use use simple quotes to wrap the **data-gtm-*** info to be able to parse the data properly.
|
47
|
+
|
48
|
+
### Bind Event
|
49
|
+
|
50
|
+
If you want to bind some event on any tag to push certain data into the **dataLayer** object, you just have to give the special data attribute **data-gtm-*** to this tag with the content you want to push to the **dataLayer** on the event, and voila! There you have it!
|
51
|
+
|
52
|
+
Here some examples of use:
|
53
|
+
|
54
|
+
```
|
55
|
+
<a id="example1" href="#" data-gtm-click='{"someKey": "hello", "otherKey": "bye"}'>Click me!</a>
|
56
|
+
```
|
57
|
+
|
58
|
+
```
|
59
|
+
<a id="example2" href="#" data-gtm-mouseover='{"someKeyMouse": "hello", "otherKeyMouse": "bye"}'>Go over me!</a>
|
60
|
+
```
|
61
|
+
|
62
|
+
And so on...
|
63
|
+
|
64
|
+
## Rails Gem
|
65
|
+
|
66
|
+
If you want to use this **JS library** with a **Rails** application, you have available the corresponding gem in order to do it more conveniently. Just follow this simple steps:
|
67
|
+
|
68
|
+
Add this line to your application's `Gemfile`:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
gem 'layer-handler'
|
72
|
+
```
|
73
|
+
|
74
|
+
And then execute:
|
75
|
+
|
76
|
+
```
|
77
|
+
$ bundle
|
78
|
+
```
|
79
|
+
|
80
|
+
Or install it yourself:
|
81
|
+
|
82
|
+
```
|
83
|
+
$ gem install layer-handler
|
84
|
+
```
|
85
|
+
|
86
|
+
After install the gem, add this into your `application.js` file:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
//= require layer_handler
|
90
|
+
```
|
91
|
+
|
92
|
+
Then create the initializer of the gem by executing:
|
93
|
+
|
94
|
+
```
|
95
|
+
rails g layer:handler:install
|
96
|
+
```
|
97
|
+
|
98
|
+
And edit the `gtm_id` config option on the new `config/initializer/layer_handler.rb` file.
|
99
|
+
|
100
|
+
And there you have it. Just put this line at the end of your Rails layout and you're ready to go:
|
101
|
+
|
102
|
+
```
|
103
|
+
<%= init_layer_handler %>
|
104
|
+
```
|
105
|
+
|
106
|
+
Now you can use the **JS library** as usual.
|
107
|
+
|
108
|
+
## TODO
|
109
|
+
|
110
|
+
- Tests!
|
111
|
+
- Add more events
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dreamingechoes/layer-handler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
**LayerHandler** is released under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/test
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
!function(a){var b={},c=[];a.LayerHandler=b,a.dataLayer=c,b.gtm_id=null,b.init=function(a){this.gtm_id=a,this.initDataLayer(),this.appendGTM(),this.bindEvents()},b.initDataLayer=function(){var a=document.getElementsByTagName("body")[0].getAttribute("data-gtm-page");this.pushData(a)},b.bindEvents=function(){for(var a=["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseover","mouseout","mouseup","keydown","keypress","keyup","abort","beforeunload","error","hashchange","load","pageshow","pagehide","resize","scroll","unload","blur","change","focus","focusin","focusout","input","invalid","reset","search","select","submit"],b=0;b<a.length;b++)this.bind(a[b])},b.bind=function(a){document.body.addEventListener(a,function(b){var c,d=b.target;do c=d.getAttribute("data-gtm-"+a),d=d.parentElement;while(d&&d.parentElement&&null===c);null!==c&&this.pushData(c)}.bind(this))},b.appendGTM=function(){var a=document.createElement("noscript"),b=document.createElement("iframe");b.setAttribute("src","//www.googletagmanager.com/ns.html?id="+this.gtm_id),b.setAttribute("height","0"),b.setAttribute("width","0"),b.setAttribute("style","display:none;visibility:hidden"),a.appendChild(b);var c=document.createElement("script");c.innerHTML="(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','"+this.gtm_id+"');";var d=document.head.firstChild,e=document.body.firstChild;d.parentNode.insertBefore(c,d),e.parentNode.insertBefore(a,e)},b.pushData=function(a){if(null!==a){var b=JSON.parse(a),d={};for(var e in b)d[e]=b[e];c.push(d)}}}(window);
|
data/gruntfile.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module.exports = function(grunt) {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
var paths = {
|
5
|
+
dist: './dist',
|
6
|
+
src: './src/layer-handler.js'
|
7
|
+
};
|
8
|
+
|
9
|
+
grunt.initConfig({
|
10
|
+
pkg: require('./package'),
|
11
|
+
|
12
|
+
build: (function() {
|
13
|
+
var build = {};
|
14
|
+
build.scripts = ['jshint', 'uglify'];
|
15
|
+
return build;
|
16
|
+
})(),
|
17
|
+
|
18
|
+
jshint: {
|
19
|
+
files: paths.src
|
20
|
+
},
|
21
|
+
|
22
|
+
uglify: {
|
23
|
+
main: {
|
24
|
+
options: {
|
25
|
+
beautify: false
|
26
|
+
},
|
27
|
+
files: {
|
28
|
+
'dist/layer-handler.min.js': 'src/layer-handler.js',
|
29
|
+
'vendor/assets/javascripts/layer-handler/layer-handler.min.js': 'src/layer-handler.js'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
},
|
33
|
+
|
34
|
+
watch: {
|
35
|
+
options: {
|
36
|
+
interrupt: true,
|
37
|
+
spawn: false
|
38
|
+
},
|
39
|
+
js: {
|
40
|
+
files: [paths.src],
|
41
|
+
tasks: ['uglify']
|
42
|
+
}
|
43
|
+
}
|
44
|
+
});
|
45
|
+
|
46
|
+
require('load-grunt-tasks')(grunt);
|
47
|
+
|
48
|
+
grunt.registerTask('default', ['uglify']);
|
49
|
+
grunt.registerTask('build', function() {
|
50
|
+
grunt.task.run(this.data);
|
51
|
+
});
|
52
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "layer/handler/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "layer-handler"
|
9
|
+
s.version = Layer::Handler::VERSION
|
10
|
+
s.authors = ["Ivan Gonzalez"]
|
11
|
+
s.email = ["xixon.sound@gmail.com"]
|
12
|
+
s.homepage = "https://dreamingechoes.github.io/layer-handler/demo"
|
13
|
+
s.summary = "Simple JS library to handle Google Tag Manager easily"
|
14
|
+
s.description = "Simple JS library to handle Google Tag Manager easily."
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
s.bindir = "exe"
|
19
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Layer
|
2
|
+
module Handler
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
desc "Creates LayerHandler initializer for your application"
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "layer_handler_initializer.rb", "config/initializers/layer_handler.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Layer
|
2
|
+
module Handler
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer "layer_handler.action_view" do |app|
|
6
|
+
ActiveSupport.on_load :action_view do
|
7
|
+
require_relative "handler/rails/view_helpers"
|
8
|
+
include Layer::Handler::ViewHelpers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor :gtm_id
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@gtm_id = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/core_ext/string/output_safety'
|
2
|
+
|
3
|
+
module Layer
|
4
|
+
module Handler
|
5
|
+
module ViewHelpers
|
6
|
+
|
7
|
+
def init_layer_handler
|
8
|
+
content_tag :script do
|
9
|
+
"LayerHandler.init('#{Layer::Handler.configuration.gtm_id}');".html_safe
|
10
|
+
end.html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/package.json
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"name": "layer-handler",
|
3
|
+
"version": "0.1.1",
|
4
|
+
"description": "Simple JS library to handle Google Tag Manager easily.",
|
5
|
+
"main": "src/layer-handler.js",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "git@github.com:dreamingechoes/layer-handler.git"
|
9
|
+
},
|
10
|
+
"dependencies": {},
|
11
|
+
"devDependencies": {
|
12
|
+
"grunt": "^0.4.5",
|
13
|
+
"grunt-contrib-jshint": "^0.11.2",
|
14
|
+
"grunt-contrib-uglify": "^0.9.1",
|
15
|
+
"grunt-contrib-watch": "^0.6.1",
|
16
|
+
"load-grunt-tasks": "^3.2.0"
|
17
|
+
},
|
18
|
+
"keywords": [
|
19
|
+
"Google Tag Manager",
|
20
|
+
"GTM",
|
21
|
+
"Javascript"
|
22
|
+
],
|
23
|
+
"author": "Ivan Gonzalez",
|
24
|
+
"license": "MIT"
|
25
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
(function(global) {
|
2
|
+
var LayerHandler = {},
|
3
|
+
dataLayer = [];
|
4
|
+
|
5
|
+
global.LayerHandler = LayerHandler;
|
6
|
+
global.dataLayer = dataLayer;
|
7
|
+
|
8
|
+
LayerHandler.gtm_id = null;
|
9
|
+
|
10
|
+
LayerHandler.init = function(gtm_id) {
|
11
|
+
this.gtm_id = gtm_id;
|
12
|
+
this.initDataLayer();
|
13
|
+
this.appendGTM();
|
14
|
+
this.bindEvents();
|
15
|
+
};
|
16
|
+
|
17
|
+
LayerHandler.initDataLayer = function() {
|
18
|
+
var data = document.getElementsByTagName('body')[0].getAttribute('data-gtm-page');
|
19
|
+
this.pushData(data);
|
20
|
+
};
|
21
|
+
|
22
|
+
LayerHandler.bindEvents = function() {
|
23
|
+
var events = ['click', 'contextmenu', 'dblclick', 'mousedown',
|
24
|
+
'mouseenter', 'mouseleave', 'mousemove', 'mouseover',
|
25
|
+
'mouseout', 'mouseup', 'keydown', 'keypress', 'keyup',
|
26
|
+
'abort', 'beforeunload', 'error', 'hashchange', 'load',
|
27
|
+
'pageshow', 'pagehide', 'resize', 'scroll', 'unload',
|
28
|
+
'blur', 'change', 'focus', 'focusin', 'focusout',
|
29
|
+
'input', 'invalid', 'reset', 'search', 'select', 'submit'];
|
30
|
+
for(var i = 0; i < events.length; i++) {
|
31
|
+
this.bind(events[i]);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
LayerHandler.bind = function(eventToBind) {
|
36
|
+
document.body.addEventListener(eventToBind, function(event) {
|
37
|
+
var element = event.target,
|
38
|
+
data;
|
39
|
+
|
40
|
+
do {
|
41
|
+
data = element.getAttribute('data-gtm-' + eventToBind);
|
42
|
+
element = element.parentElement;
|
43
|
+
} while (element && element.parentElement && data === null);
|
44
|
+
|
45
|
+
if (data !== null) {
|
46
|
+
this.pushData(data);
|
47
|
+
}
|
48
|
+
}.bind(this));
|
49
|
+
};
|
50
|
+
|
51
|
+
LayerHandler.appendGTM = function() {
|
52
|
+
var gtm_no_script = document.createElement('noscript'),
|
53
|
+
gtm_no_script_iframe = document.createElement('iframe');
|
54
|
+
|
55
|
+
gtm_no_script_iframe.setAttribute('src', '//www.googletagmanager.com/ns.html?id=' + this.gtm_id);
|
56
|
+
gtm_no_script_iframe.setAttribute('height', '0');
|
57
|
+
gtm_no_script_iframe.setAttribute('width', '0');
|
58
|
+
gtm_no_script_iframe.setAttribute('style', 'display:none;visibility:hidden');
|
59
|
+
gtm_no_script.appendChild(gtm_no_script_iframe);
|
60
|
+
|
61
|
+
var gtm_script = document.createElement('script');
|
62
|
+
gtm_script.innerHTML = "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" +
|
63
|
+
"new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," +
|
64
|
+
"j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" +
|
65
|
+
"'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" +
|
66
|
+
"})(window,document,'script','dataLayer','" + this.gtm_id + "');";
|
67
|
+
|
68
|
+
var appendHead = document.head.firstChild,
|
69
|
+
appendBody = document.body.firstChild;
|
70
|
+
appendHead.parentNode.insertBefore(gtm_script, appendHead);
|
71
|
+
appendBody.parentNode.insertBefore(gtm_no_script, appendBody);
|
72
|
+
};
|
73
|
+
|
74
|
+
LayerHandler.pushData = function(data) {
|
75
|
+
if(data !== null) {
|
76
|
+
var parsed_data = JSON.parse(data),
|
77
|
+
temp = {};
|
78
|
+
for(var key in parsed_data) {
|
79
|
+
temp[key] = parsed_data[key];
|
80
|
+
}
|
81
|
+
dataLayer.push(temp);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
})(window);
|
@@ -0,0 +1 @@
|
|
1
|
+
!function(a){var b={},c=[];a.LayerHandler=b,a.dataLayer=c,b.gtm_id=null,b.init=function(a){this.gtm_id=a,this.initDataLayer(),this.appendGTM(),this.bindEvents()},b.initDataLayer=function(){var a=document.getElementsByTagName("body")[0].getAttribute("data-gtm-page");this.pushData(a)},b.bindEvents=function(){for(var a=["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseover","mouseout","mouseup","keydown","keypress","keyup","abort","beforeunload","error","hashchange","load","pageshow","pagehide","resize","scroll","unload","blur","change","focus","focusin","focusout","input","invalid","reset","search","select","submit"],b=0;b<a.length;b++)this.bind(a[b])},b.bind=function(a){document.body.addEventListener(a,function(b){var c,d=b.target;do c=d.getAttribute("data-gtm-"+a),d=d.parentElement;while(d&&d.parentElement&&null===c);null!==c&&this.pushData(c)}.bind(this))},b.appendGTM=function(){var a=document.createElement("noscript"),b=document.createElement("iframe");b.setAttribute("src","//www.googletagmanager.com/ns.html?id="+this.gtm_id),b.setAttribute("height","0"),b.setAttribute("width","0"),b.setAttribute("style","display:none;visibility:hidden"),a.appendChild(b);var c=document.createElement("script");c.innerHTML="(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','"+this.gtm_id+"');";var d=document.head.firstChild,e=document.body.firstChild;d.parentNode.insertBefore(c,d),e.parentNode.insertBefore(a,e)},b.pushData=function(a){if(null!==a){var b=JSON.parse(a),d={};for(var e in b)d[e]=b[e];c.push(d)}}}(window);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into bootstrap_sb_admin_base_v2.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require ./layer-handler/layer-handler.min
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: layer-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Gonzalez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple JS library to handle Google Tag Manager easily.
|
14
|
+
email:
|
15
|
+
- xixon.sound@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- .travis.yml
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/test
|
29
|
+
- dist/layer-handler.min.js
|
30
|
+
- gruntfile.js
|
31
|
+
- layer-handler.gemspec
|
32
|
+
- lib/generators/layer/handler/install_generator.rb
|
33
|
+
- lib/generators/layer/handler/templates/layer_handler_initializer.rb
|
34
|
+
- lib/layer/handler.rb
|
35
|
+
- lib/layer/handler/rails/view_helpers.rb
|
36
|
+
- lib/layer/handler/version.rb
|
37
|
+
- lib/tasks/layer/handler_tasks.rake
|
38
|
+
- package.json
|
39
|
+
- src/layer-handler.js
|
40
|
+
- vendor/assets/javascripts/layer-handler/layer-handler.min.js
|
41
|
+
- vendor/assets/javascripts/layer_handler.js
|
42
|
+
homepage: https://dreamingechoes.github.io/layer-handler/demo
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.14
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Simple JS library to handle Google Tag Manager easily
|
66
|
+
test_files: []
|