Module: IntercomRails::ScriptTagHelper

Defined in:
lib/intercom-rails/script_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#intercom_script_tag(user_details = nil, options = {}) ⇒ String

Generate an intercom script tag.

Examples:

basic example

<%= intercom_script_tag({ :app_id => "your-app-id",
                          :user_id => current_user.id,
                          :email => current_user.email,
                          :custom_data => { :plan => current_user.plan.name },
                          :name => current_user.name }) %>

with widget activator for launching then widget when an element matching the css selector '#Intercom' is clicked.

<%= intercom_script_tag({ :app_id => "your-app-id",
                          :user_id => current_user.id,
                          :email => current_user.email,
                          :custom_data => { :plan => current_user.plan.name },
                          :name => current_user.name },
                          {:widget => {:activator => "#Intercom"}},) %>

Parameters:

  • user_details (Hash) (defaults to: nil)

    a customizable hash of user details

  • options (Hash) (defaults to: {})

    an optional hash for secure mode and widget customisation

Options Hash (user_details):

  • :app_id (String)

    Your application id

  • :user_id (String)

    unique id of this user within your application

  • :email (String)

    email address for this user

  • :name (String)

    the users name, optional but useful for identify people in the Intercom App.

  • :custom_data (Hash)

    custom attributes you'd like saved for this user on Intercom.

Options Hash (options):

  • :widget (String)

    a hash containing a css selector for an element which when clicked should show the Intercom widget

  • :secret (String)

    Your app secret for secure mode

Returns:

  • (String)

    Intercom script tag


30
31
32
33
34
35
36
37
38
# File 'lib/intercom-rails/script_tag_helper.rb', line 30

def intercom_script_tag(user_details = nil, options={})
  controller.instance_variable_set(IntercomRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE, true) if defined?(controller)
  options[:user_details] = user_details if user_details.present?
  options[:find_current_user_details] = !options[:user_details]
  options[:find_current_company_details] = !(options[:user_details] && options[:user_details][:company])
  options[:controller] = controller if defined?(controller)

  ScriptTag.generate(options)
end