Giter VIP home page Giter VIP logo

Comments (7)

astorm avatar astorm commented on May 29, 2024

Adding this as a third parameter to the track calls.

analytics.track("Wishlisted Product",
segment_analytics_addedtowishlist.params,
{"library":{"name":"analytics-magento","version":"0.0.1"}}    );

I'm a little unclear how how this should be added to page/identity/alias -- especially page since a two parameter call to page is a category request?

window.analytics.page(segment_analytics_page.full_category_name, segment_analytics_page.page_title);      

I'm also a little unclear on why you included a PHP array above that has a top level key context after showing the syntax for track is to pass the context in as a third item.

from analytics-magento.

ianstormtaylor avatar ianstormtaylor commented on May 29, 2024

Sure thing, we're actually just about to change the way this works for the Javascript library, so here's an updated version for the new API in Javascript only:

analytics.track('event', { property: 'something' }, {
  context: {
    library: {
      name: 'analytics-magento',
      version: '0.0.1'
    }
  }
});

The difference is that the options object is now nested (to provide for other potential API features other than context). This changed should be merged tomorrow or the next day, so we can make it now.

The other methods have their options object like so:

analytics.identify(userId, traits, options);
analytics.track(event, properties, options);
analytics.page(category, name, properties, options);
analytics.group(groupId, traits, options);
analytics.alias(userId, options);

So each time you see options, we should replace that with:

{
  context: {
    library: {
      name: 'analytics-magento',
      version: '0.0.1'
    }
  }
}

from analytics-magento.

ianstormtaylor avatar ianstormtaylor commented on May 29, 2024

The PHP library (and other libraries) are structured slightly differently, since they are stateless. They have all of their parameters as keys in a top-level array, like so:

Analytics::track(array(
  "userId" => "user",
  "event" => "event",
  "properties" => array(),
  "context" => array(
    "library" => array(
      "name" => "analytics-magento",
      "version" => "0.0.1"
    )
  )
));

And all of the PHP calls have the same top-level structure, so they would all put context in an extra, top-level key.

Does that make sense? Let me know if you have questions.

from analytics-magento.

ianstormtaylor avatar ianstormtaylor commented on May 29, 2024

Actually, I just realized, ignore the PHP stuff.

I think you're exposing a Magento model that wraps our PHP library? I just realized we shouldn't actually be exposing a proper PHP API, we should expose it in a way that just adds the calls they make there to the page, like we do with WordPress: https://github.com/segmentio/analytics-wordpress/blob/master/analytics-wordpress.php#L150

from analytics-magento.

astorm avatar astorm commented on May 29, 2024

Ian thanks. One last question — what should I be passing in on the page calls that aren't categories? i.e., a regular page call looks like

analytics.page('Some Page');

Do I just do this?

analytics.page('Some Page',null,null,{...context...});

Or will that be interpreted as the category form

analytics.page(category, name, properties, options);

from analytics-magento.

ianstormtaylor avatar ianstormtaylor commented on May 29, 2024

For those ones, the API will handle overloading for you if you want, so for example:

analytics.page(name, properties, options);

Works fine. But the nulls also work if that's clearer for you. Only reason properties is required there is because options is also an object, so we can't tell them apart.

Does that make sense?

from analytics-magento.

astorm avatar astorm commented on May 29, 2024

Yup, makes sense. All calls (identify, track, page, alias, we're not using group) should have the context object now.

from analytics-magento.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.