Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fictionindustries created an issue. See original summary.

Darren Shelley’s picture

I needed this for a project I'm working on.
I've completed the upgrade from 7 to 8 (based on the latest stable release 7.x-1.1)
Any and all feedback greatly appreciated.

As per 7.x-1.1 I have implemented the segmentio_info hook and the optional user/node functionality out of the box.

The implementation has changed slightly to make the Javascript more cacheable and reduce the amount of potentially rogue javascript

Instead of returning custom javascript you alter a variable array. For instance:

/**
 * Segment.io callback; Set attributes for analytics.js calls.
 */
function example_segmentio_mytrackinginfo(&$variables = []) {
  // Identify the user.
  $variables['identify']['userId'] = 1;
  $variables['identify']['traits']['name'] = 'admin';
  $variables['identify']['traits']['email'] = 'example@example.com';

  // Identify the page.
  $variables['page']['category'] = 'basic page';
  $variables['page']['name'] = 'Cookie policy';
  $variables['page']['properties']['nid'] = 1;
  $variables['page']['properties']['uid'] = 1;

  // Alias associated identified users with group.
  $variables['group']['groupId'] = 'Group Name';
  $variables['group']['traits']['address1'] = '1 Example Lane';

  // Alias two identities.
  $variables['alias']['userId'] = 2;
  $variables['alias']['previousId'] = 1;

  // Track an event.
  $variables['track'][] = [
    'event' => 'Downloaded a PDF',
    'properties' => [
      'pdf_name' => 'examplepdf.pdf',
    ],
  ];
}

New Functionality
I've created an event_track function that will trigger an analytics.track() call on the successive page load. For Instance:
segmentio_set_track_event('Peeling a fruit', array('fruit' => 'banana');
This should make it easier to track dynamic interactions.

Darren Shelley’s picture

FileSize
10.01 KB

Please find attached zip of the Drupal 8 version

gobinathm’s picture

I will review this today. Would it be possible for you to maybe submit this as a patch ?

Darren Shelley’s picture

Darren Shelley’s picture

Status: Active » Needs review

Updating the status to "Needs Review"

Status: Needs review » Needs work

The last submitted patch, 5: segmentio-upgrade_to_drupal_8-2753275-4.patch, failed testing.

Darren Shelley’s picture

Please disregard the PHPLint failure, this stems from the fact the issue is tagged 7.x-1.x but the code is D8 where use of short array syntax is encouraged (Drupal 8 requires version PHP 5.5.9 or later).

siliconmeadow’s picture

I've applied the patch file from #5, and when I try to enable the module, I get the error:

Error: Redefinition of parameter $form_state in /var/www/drupalvm/drupal/web/modules/contrib/segmentio/src/Form/SegmentioAdminSettingsForm.php, line 45

I could supply the whole stack trace, but it would appear that:

public function buildForm(array $form_state, FormStateInterface $form_state) {

should actually be:

public function buildForm(array $form, FormStateInterface $form_state) {

siliconmeadow’s picture

FileSize
30.38 KB

Also with the segmentio.links.menu.yml file, having the link in the description caused the admin page to render like this:

I've tried a variety of different variations, but I could only get it to work was by removing the link.

siliconmeadow’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: drupal_8_roadmap-2753275-11.patch, failed testing.

siliconmeadow’s picture

Status: Needs work » Needs review

I converted this back to Needs review, due to the reason Darren Shelley mentioned in #8.

It would be useful if this could be made the 8.x-1.x-dev branch so we can get the true benefit of the testbot.

Sharique’s picture

Status: Needs review » Reviewed & tested by the community

The code looks good. Patch applied perfectly. +1 for RTBC.
I didn't have segmantio account, so couldn't test it with it.

Darren Shelley’s picture

Good catch @siliconmeadow. +1 for RTBC

gobinathm’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.