1

I use Drupal 7 and I want to track an action when user creates a node of a specific content type.

I installed the Facebook Pixel and Facebook Tracking Pixel modules, but they don't support my needs. Is there any way to implement this?

0

I would use the Rules module, which allows for dozens of variations of tracking. As an example, here is a prototype of a rule, in Rules export format, to illustrate the possibilities:

{ "rules_find_links_in_body" : {
    "LABEL" : "Find links in body",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--article" : { "bundle" : "article" } },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      },
      { "OR" : [
          { "text_matches" : {
              "text" : [ "node:body:value" ],
              "match" : "http(|s):\/\/+",
              "operation" : "regex"
            }
          },
          { "text_matches" : {
              "text" : [ "node:body:value" ],
              "match" : "ANotAllowedTextStringInBody",
              "operation" : "regex"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "Node body contains an URL ..." } }
    ]
  }
}

Some more details about the above prototype rule:

  • Rules Event = After saving new content of type "Article" (adapt the type to fit your needs).
  • Rules Conditions:
    • Check if the current user is an authenticated user.
    • Perform a text comparison, using a Regular Expression as the Comparison operation (which you can perfectly do in Rules, without using the PHP filter for it). For the actual regular expression, this rule uses http(|s)://+, which will discover strings that start with either http:// or https://. Should you have additional / similar requirements to discover variations of this (say some other string like ANotAllowedTextStringInBody), another Rules Condition (with an OR) will take care of that also.
  • Rules Action = Show a message on the site (adapt the message to fit your needs), and/or add other relevant Rules Actions ... Such as:

Voilà, easy as that ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.