简体   繁体   English

在 Wordpress 中使用 Learndash Hook 进行 ActiveCampaign 事件跟踪

[英]ActiveCampaign Event Tracking Using Learndash Hook in Wordpress

I'm a bit of a newbie to PHP and wordpress (the dreaded opener), and I'm trying to add some functionality to an e-learning site I've built out using the LearnDash plugin for Wordpress.我是 PHP 和 wordpress(可怕的开瓶器)的新手,我正在尝试将一些功能添加到我使用适用于 ZDCEC9B13BC09FCFA545ZA 的 LearnDash 插件构建的电子学习网站。

One of the ways I'm tracking user progress is with ActiveCampaign.我跟踪用户进度的方法之一是使用 ActiveCampaign。 The site tracking is installed and working great, but I'm trying to get an event to be logged in AC when a user completes a course.站点跟踪已安装并且运行良好,但我试图在用户完成课程时让事件登录到 AC。 There's a LearnDash hook available for this ( https://www.learndash.com/support/docs/developers/hooks-and-filters/ ), and the actual event code is available from the Active Campaign tracking page.有一个可用的 LearnDash 钩子 ( https://www.learndash.com/support/docs/developers/hooks-and-filters/ ),实际的事件代码可从 Active Campaign 跟踪页面获得。

I've ended up with the following code:我最终得到了以下代码:


//learndash hook:
add_action("learndash_course_completed", sendEmail,5,1);

//defining user's email to use in tracking event code:
function sendEmail(){
    $current_user = wp_get_current_user();
    $userEmail = $user->user_email;

//Event Tracking code as per the Active Campaign Page - Account info omitted

    $curl = curl_init();
       curl_setopt($curl, CURLOPT_URL, "https://trackcmp.net/event");
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POST, true);
       curl_setopt($curl, CURLOPT_POSTFIELDS, array(
       "actid" => "ACCOUNT ID NUMBER",
       "key" => "TRACKING KEY NUMBER",
       "event" => "EVENT NAME",
       "eventdata" => "User Has Completed the course",
       "visit" => json_encode(array(
               // If you have an email address, assign it here.
               "email" => $userEmail,
           )),
       ));

       $result = curl_exec($curl);
       if ($result !== false) {
           $result = json_decode($result);
           if ($result->success) {
               echo 'Success! ';
           } else {
               echo 'Error! ';
           }

           echo $result->message;
       } else {
           echo 'cURL failed to run: ', curl_error($curl);
}
};

It's not firing when the user completes a course and I'm not sure what I've done wrong.当用户完成课程并且我不确定我做错了什么时,它不会触发。 Probably something really obvious.可能是非常明显的事情。 Any thoughts?有什么想法吗?

Thanks!谢谢!

Found it, Like an idiot, I'd called the $user variable.找到它,像个白痴一样,我调用了 $user 变量。 when it was actually defined as $current-user.当它实际上被定义为 $current-user 时。

All good!都好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM