When someone starts a course, it needs to get 'read and analyze' access to a Google Analytics account. There is a GA API for that which should use the email address of the course taker as a variable. The API code is:
POST https://www.googleapis.com/analytics/v3/management/accounts/xxxxx/webproperties/UA-xxxxxxxx-1/profiles/xxxxx/entityUserLinks
{
"userRef": {
"email": "usermailaddress@test.com"
},
"permissions": {
"local": [
"READ_AND_ANALYZE"
]
}
}
I read something about the hook wplms_start_course, just don't know how to get started. Any help would be much appreciated.
Please add your custom code in wplms customizer.php file and post the value like this :
add_action('wplms_course_start_after_timeline','gacpde',10,1);
function gacode($course_id){
$user_id = get_current_user_id();
$user = get_user_by( 'id', $user_id);
$course_status = bp_course_get_user_course_status($user_id,$precourse);
if( $course_status == 1){
?>
<script>
//send code to GA via js
<?php echo $user->user_email; //will echo the user email
?>
</script>
<?php
}
}
Please post the json object to the url via js .