Thank you for your module it has helped me to configure webform in order to send data to Microsoft Dynamics CRM with http://clickdimensions.com/

The only things to add in the module is the referer line 161. Maybe this should be added in the module

  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded', 'Referer' => $GLOBALS['base_url'] ),

There are 3 others steps:
1/ Add an input fields with cd_visitorkey name in the webform
2/ Add js required by clickdimension

3/ Add js to get the cookie inside input field

    /*SET COOKIE TO FORM*/
    function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
    } 
    var cooki = getCookie("cuvid");
    //console.log(cooki);
    $(".page-node-619 input[name$='submitted[cd_visitorkey]']").val(cooki);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

creatile created an issue. See original summary.

frodeste’s picture

Thank you so much for this tip.

A few questions. I can't find the JS you are refering to. Is it the Click Dimensions tracking script? Or https://az124611.vo.msecnd.net/web/v10/cdform.jquery.js

Where would be the best place to add this script? Template files?

As to the JS in item 3 above, where would I place this script?

As to the change in 1, adding this I think will be broken upon updating the module. Any comments to this?

Kaz de Groot’s picture

I'm working on CD integration for a project as well.
I have included a patch that applies the referrer header as shown in the original post. I agree that should probably be included, if not made a setting.
For collecting the cd_visitorkey, I prefer to handle it serverside, for which I use a small module that implements the following hook:

function [module]_webform_submission_presave($node, &$submission) {
  if (isset($_COOKIE['cuvid'])) {
    $cuvid = $_COOKIE['cuvid'];
    foreach ($node->webform['components'] as $c) {
      if ($c['form_key'] == 'cd_visitorkey') {
        $submission->data[$c['cid']][0] = $cuvid;
      }
    }
  }
}

If the cookie cuvid is set, it checks any submitted webform for a cd_visitorkey field, and inserts the cookies value. Because it happens server side, the cd_visitorkey field can be the secure hidden variant, that doesn't involve a hidden input field in the form.

#2: You should probably add the script from step 2 with a tag manager. That way, you're not hardcoding tag information in your theme or modules.

frodeste’s picture

We have paid for a developer to create a project for this:

Source will be at https://github.com/ProsessPilotene/DrupalWebFormClickDimensions

And project at https://www.drupal.org/sandbox/frodeste/2699377

We would love to work together on this.

The core feature is that we will use CD's web capture forms.

pamelalies’s picture

For anyone still struggling to get this working, I have one more piece of info to add that might help you if you've followed the above and it's still not working for you.

The steps I used were:
1. Applied the patch to include the referrer header to the Webform Remote Post module.
2. Added the secure hidden input field with cd_visitorkey name in the webform
3. I used Kaz de Groot's server-side code to collect the cd_visitorkey data. I wanted to avoid any potential issues for people who disable javascript in their browsers, and also we're trying to minimize our scripts whenever possible because we already have a lot of scripts on our site.
4. We already had the ClickDimensions base tracking script on all pages of our site. We have that in one of our common template files, since it seldom changes.

So all that seemed to be set up right (and it was), but I still wasn't getting my form data posted through to CRM. The key for our site was the following. Even though the ClickDimensions documentation (here: http://help.clickdimensions.com/steps-to-check-before-using-form-capture...), under Step 3: Creating Form Field records in CRM, then the "Important!" section, says that "The Form Field ID field on the ClickDimensions Form Field record is incredibly important when using Form Capture. For each Form Field Record, the ID field value must match the name value in the HTML form field.", - that recommendation isn't correct in this case using Drupal Webform and programmatic form capture.

Going by that information, I thought that the ClickDimensions form field ID in CRM for say the "First Name" field would need to be "submitted[first_name]", because that is what Webform uses as the name attribute for that field - as seen when you view source on the form. The full HTML for that field looks like the below.
<input required="required" class="form-control form-text required" type="text" id="edit-submitted-first-name" name="submitted[first_name]" value="" size="60" maxlength="128" />

It turns out what you really need to use as the Form Field ID field on the ClickDimensions Form Field record in CRM has to match whatever Webform field key you used for your field on the Drupal side. For me, the field key for my first name field is "first_name". When I switched all my form capture fields in CRM to use IDs that matched the Drupal Webform field keys for each field, THEN everything started working correctly and all my data was flowing in to CRM!

Just thought that might help someone else out there who wasn't able to get everything working correctly even after following the above steps. :-)

Thanks so much to all you previous posters who gave me enough info to go on to get this working for my site as well!

roelal’s picture

I 'd stay away from vendor specific implementations. Just add a hook so the request can be modified before sending it. Then someone else's clickdimensions module can intercept before the actual POST request, and add in the referer header and cu_vid query param.

https://support.clickdimensions.com/hc/en-us/articles/115001157953-Progr...