Sha256: 231f51f49800bd0ff13d8f387a364402732c11c0b65fc6603d254fb692a2b783

Contents?: true

Size: 1.85 KB

Versions: 17

Compression:

Stored size: 1.85 KB

Contents

module Analytical
  module Modules
    class MicrosoftAds
      include Analytical::Modules::Base

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

      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

      #
      # Define conversion events in analytical.yml like:
      #
      # microsoft_ads:
      #   'Some Event':
      #     id: 55555555-6666-7777-8888-111111111111
      def event(name, *args)
        return '' unless @initializing

        data = args.first || {}
        if conversion = options[name.to_sym]
          conversion.symbolize_keys!
          js = <<-HTML
          <script type="text/javascript">if (!window.mstag) mstag = {loadTag : function(){},time : (new Date()).getTime()};</script>
          <script id="mstag_tops" type="text/javascript" src="//flex.atdmt.com/mstag/site/#{conversion[:id]}/mstag.js"></script>
          <script type="text/javascript"> mstag.loadTag("conversion", {cp:"5050",dedup:"1"})</script>
          <noscript>
            <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>
          </noscript>
          HTML
          js
        else
          "<!-- No Microsoft Ads Conversion for: #{name} -->"
        end
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
analytical-3.0.12 lib/analytical/modules/microsoft_ads.rb
analytical-3.0.11 lib/analytical/modules/microsoft_ads.rb
analytical-3.0.9 lib/analytical/modules/microsoft_ads.rb
analytical-3.0.8 lib/analytical/modules/microsoft_ads.rb
analytical-3.0.7 lib/analytical/modules/microsoft_ads.rb
analytical-3.0.6 lib/analytical/modules/microsoft_ads.rb
gsiener-analytical-2.10.2 lib/analytical/modules/microsoft_ads.rb
gsiener-analytical-2.10.1 lib/analytical/modules/microsoft_ads.rb
analytical-2.11.0 lib/analytical/modules/microsoft_ads.rb
analytical-2.10.0 lib/analytical/modules/microsoft_ads.rb
gsiener-analytical-2.10.0 lib/analytical/modules/microsoft_ads.rb
analytical-2.9.0 lib/analytical/modules/microsoft_ads.rb
analytical-2.8.0 lib/analytical/modules/microsoft_ads.rb
analytical-2.7.2 lib/analytical/modules/microsoft_ads.rb
analytical-2.7.1 lib/analytical/modules/microsoft_ads.rb
analytical-2.7.0 lib/analytical/modules/microsoft_ads.rb
analytical-2.6.0 lib/analytical/modules/microsoft_ads.rb