Jump to content

Help with Hook code for javascript?


Sync365License

Recommended Posts

Hey All,

Really struggling to work out how I can execute the script for FreshSales suite. 

I want to create the contact on clientAdd, but cannot work it out.

The info for it is here: How to set up Freshworks CRM Tracking Code? : Freshsales Suite

From what I understand, the tracking code loads a jquery library, and the code to create the contact uses that to make the contact. 
I just cannot work out how to get it to work via the hook

 

Any help appreciated.

Here is what i have

<?php

if (!defined('WHMCS'))
    die('You cannot access this file directly.');

function create_fs_contact($vars) {

var new_contact =
{
      "First name": $vars['firstname'], //Replace with first name of the user
      "Last name": $vars['lastname'],  //Replace with last name of the user
      "Email": $vars['email'], //Replace with email of the user
      "Alternate contact number": $vars['phonenumber'], //Replace with a custom field
      "company": {
          "Name": $vars['companyname'], //Replace with company name
          "Website": array_pop(explode('@', $vars['email'])) //Replace with website of company
      }
};
var identifier = $vars['email'];
fwcrm.identify(identifier, new_contact)

}


add_hook('ClientAdd', 1, 'create_fs_contact');

 

Link to comment
Share on other sites

  • 2 weeks later...

The code Freshworks provides appears to be JavaScript that is intended to run client-side in the browser.  It cannot be executed from the server using PHP in this way. To integrate this code with WHMCS you would need to either 1) use a different hook to insert JavaScript (as a text string) into the page header or 2) modify one or more client area templates to include the custom JavaScript. I think the second option will probably work best for you in this case. Here are a few of the Smarty templates that you might find useful for integrating CRM lead tracking:

/templates/six/contact.tpl - contact form (six template)
/templates/six/clientregister.tpl - direct client registration (six template)
/templates/twenty-one/contact.tpl - contact form (twenty-one template)
/templates/twenty-one/clientregister.tpl - direct client registration (twenty-one template)
/templates/orderforms/standard_cart/checkout.tpl - client registration during order checkout

Note: default template paths are frequently overwritten during WHMCS updates. A child theme should be created and used for any changes to template files such as those listed above.

Edited by SethMcCauley
Additional info on client templates
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated