Class: Recipes::GoogleTagManager

Inherits:
Rails::AppBuilder
  • Object
show all
Defined in:
lib/potassium/recipes/google_tag_manager.rb

Instance Method Summary collapse

Instance Method Details

#add_content_security_policyObject



25
26
27
28
29
30
31
# File 'lib/potassium/recipes/google_tag_manager.rb', line 25

def add_content_security_policy
  inject_into_file(
    'config/initializers/content_security_policy.rb',
    content_security_policy_code,
    before: '# Report violations without enforcing the policy.'
  )
end

#add_google_tag_managerObject



18
19
20
21
22
23
# File 'lib/potassium/recipes/google_tag_manager.rb', line 18

def add_google_tag_manager
  copy_tag_manager_files
  append_to_file '.env.development', "GTM_CONTAINER_ID=\n"
  include_tag_manager
  add_content_security_policy
end

#askObject



2
3
4
5
6
7
8
# File 'lib/potassium/recipes/google_tag_manager.rb', line 2

def ask
  use_google_tag_manager = answer(:google_tag_manager) do
    Ask.confirm 'Do you want to use Google Tag Manager?'
  end

  set(:google_tag_manager, use_google_tag_manager)
end

#copy_tag_manager_filesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/potassium/recipes/google_tag_manager.rb', line 33

def copy_tag_manager_files
  copy_file(
    '../assets/app/views/shared/_gtm_head.html.erb',
    'app/views/shared/_gtm_head.html.erb',
    force: true
  )

  copy_file(
    '../assets/app/views/shared/_gtm_body.html.erb',
    'app/views/shared/_gtm_body.html.erb',
    force: true
  )
end

#createObject



10
11
12
# File 'lib/potassium/recipes/google_tag_manager.rb', line 10

def create
  install if selected?(:google_tag_manager)
end

#include_tag_managerObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/potassium/recipes/google_tag_manager.rb', line 47

def include_tag_manager
  inject_into_file(
    'app/views/layouts/application.html.erb',
    render_string('shared/gtm_head'),
    before: '</head>'
  )

  inject_into_file(
    'app/views/layouts/application.html.erb',
    render_string('shared/gtm_body'),
    after: '<body>'
  )
end

#installObject



14
15
16
# File 'lib/potassium/recipes/google_tag_manager.rb', line 14

def install
  add_google_tag_manager
end