Class: Analytical::Modules::MicrosoftAds

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/analytical/modules/microsoft_ads.rb

Instance Attribute Summary

Attributes included from Base

#command_store, #initialized, #options, #tracking_command_location

Instance Method Summary collapse

Methods included from Base

#init_location, #init_location?, #process_queued_commands, #protocol, #queue

Constructor Details

#initialize(options = {}) ⇒ MicrosoftAds



6
7
8
9
# File 'lib/analytical/modules/microsoft_ads.rb', line 6

def initialize(options={})
  super
  @tracking_command_location = :body_append
end

Instance Method Details

#event(name, *args) ⇒ Object

Define conversion events in analytical.yml like:

microsoft_ads:

'Some Event':
  id: 55555555-6666-7777-8888-111111111111


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/analytical/modules/microsoft_ads.rb', line 35

def event(name, *args)
  return '' unless @initializing

  data = args.first || {}
  if conversion = options[name.to_sym]
    conversion.symbolize_keys!
    js = "    <script type=\"text/javascript\">if (!window.mstag) mstag = {loadTag : function(){},time : (new Date()).getTime()};</script>\n    <script id=\"mstag_tops\" type=\"text/javascript\" src=\"//flex.atdmt.com/mstag/site/\#{conversion[:id]}/mstag.js\"></script>\n    <script type=\"text/javascript\"> mstag.loadTag(\"conversion\", {cp:\"5050\",dedup:\"1\"})</script>\n    <noscript>\n      <iframe src=\"//flex.atdmt.com/mstag/tag/\#{conversion[:id]}/conversion.html?cp=5050&dedup=1\" frameborder=\"0\" scrolling=\"no\" width=\"1\" height=\"1\" style=\"visibility:hidden; display:none\"></iframe>\n    </noscript>\n    HTML\n    js\n  else\n    \"<!-- No Microsoft Ads Conversion for: \#{name} -->\"\n  end\nend\n"

#init_javascript(location) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/analytical/modules/microsoft_ads.rb', line 11

def init_javascript(location)
  init_location(location) do
    @initializing = true
    html = "<!-- Analytical Init: Microsoft Ads -->\n"
    event_commands = []
    @command_store.commands.each do |c|
      if c[0] == :event
        event_commands << event(*c[1..-1])
      end
    end
    html += event_commands.join("\n")
    @command_store.commands = @command_store.commands.delete_if {|c| c[0] == :event }
    @initializing = false

    html
  end
end