Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump / Upgrade Snowplow to v3 (RENAMED) #202

Closed
markojak opened this issue Aug 24, 2021 · 15 comments · Fixed by #222
Closed

Bump / Upgrade Snowplow to v3 (RENAMED) #202

markojak opened this issue Aug 24, 2021 · 15 comments · Fixed by #222

Comments

@markojak
Copy link

markojak commented Aug 24, 2021

I need to be able to enable the Snowplow Debugger Plugin which seems to not ship with the snowplow tracker (sp.js) but only with their Snowplow plugins.umd.zip

@DavidWells How would the Analytics wrapper enable me to load additional Snowplow plugins that are not already included in sp.js ?

The way that the GetAnalytics seems to handle existing plugins is with the instance.plugins.snowplow.enableActivityTracking({ })

As per Snowplow documentation here they suggest to do the following

window.snowplow('addPlugin', 
  "https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-debugger@latest/dist/index.umd.min.js",
  ["snowplowDebugger", "DebuggerPlugin"]
);

When trying to do instance.plugins.snowplow.enableDebugger() then we will get a
"AppContext.tsx:139 Uncaught (in promise) TypeError: instance.plugins.snowplow.enableDebugger is not a function"

However with instance.plugins.snowplow.enableFormTracking() this works because it ships with sp.js

@markojak markojak changed the title Snowplow loading Plugins not included in sp.js (Debugger Plugin) Loading Snowplow Plugins not included in sp.js (Debugger Plugin) Aug 24, 2021
@markojak
Copy link
Author

Update: I tried to recompile the entire sp.js tracker to bundle the Debugger into sp.js as a workaround but I still can't figure out how to instantiate the Debugger using Analytics

    analytics.on('initialize:snowplow', ({ instance }) => {
        instance.plugins.snowplow.enableActivityTracking({
            minimumVisitLength: 30,
            heartbeatDelay: 10,
        })
        instance.plugins.snowplow.enableLinkClickTracking()
        instance.plugins.snowplow.enableFormTracking()
        instance.plugins.snowplow.enableDebugger()
    })

@markojak
Copy link
Author

@DavidWells Referencing this issue here from Snowplow Tracker it makes sense that one should selectively load the JS for the debugger and not bundle it in sp.js as this would then mean that all of our websites would have LOG_LEVEL 4 Debugging on

Does the Snowplow plugin currently provide for an ability to load the Debugger such as described?

window.snowplow('addPlugin', 
  "https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-debugger@latest/dist/index.umd.min.js",
  ["snowplowDebugger", "DebuggerPlugin"],
  [ 4 ] // 4 = Info logs
);

@paulboocock
Copy link
Contributor

Plugins only work in v3 of the JS tracker, so this #178 would need completing first before this would work. I started working on #178 but haven't had the chance to wrap it up yet.

@paulboocock
Copy link
Contributor

Extra note: as the API changed between v2 and v3, compiling a v3 and trying to use it with this plugin will not work and events will not be tracked as expected.

@markojak
Copy link
Author

markojak commented Aug 25, 2021

Hi @paulboocock very weird to see you here as well but thanks for being so attentive to this.
We are currently using a Self-hosted V3 of the tracker

The enableLinkClickTracking() and enableFormTracking() Plugin's using Analytics seem to work perfectly.

    analytics.on('initialize:snowplow', ({ instance }) => {
        instance.plugins.snowplow.enableActivityTracking({
            minimumVisitLength: 30,
            heartbeatDelay: 10,
        })
        instance.plugins.snowplow.enableLinkClickTracking()
        instance.plugins.snowplow.enableFormTracking()
        // instance.plugins.snowplow.enableDebuggerPlugin() // FIXME: Not yet working . Investigating
    }}

@markojak
Copy link
Author

markojak commented Aug 25, 2021

EDIT Apologies just read your other message on Snowplow.

"The tracker plugins (like debugger) don't work with v2 of the tracker, and the getanalytics.io plugin only works with v2 at the moment. "

I didn't know this - We are using a V3 sp.js with our GetAnalytics plugin. It all seems to work fine?

@paulboocock
Copy link
Contributor

paulboocock commented Aug 25, 2021

So it'll work fine in most cases, any API call with no parameters will be 100% ok:

        instance.plugins.snowplow.enableLinkClickTracking()
        instance.plugins.snowplow.enableFormTracking()

Anything with parameters will have changed between v2 and v3 which means all the typings are wrong in the @analytics/snowplow plugin now. If you're using good ol' JavaScript then this is fine because you can just pass the new parameter structure in:

        instance.plugins.snowplow.enableActivityTracking({
            minimumVisitLength: 30,
            heartbeatDelay: 10,
        })

However, if you're using TypeScript then this won't compile because you'll get a type error. In @analytics/snowplow, currently the definition of enableActivityTracking is:

      /**
       * Enables Activity Tracking https://bit.ly/3hBM6QK
       * Generates page ping events based on user activity on page
       * Should be called before first page view event
       * @param {number} [minimumVisitLength] - Minimum visit length before first page ping event fires
       * @param {number} [heartbeat] - Period where user must be active to fire the next page ping
       */
      enableActivityTracking(minimumVisitLength, heartbeat) {
        const { name } = config;
        snowplow(
          `enableActivityTracking:${name}`,
          minimumVisitLength,
          heartbeat
        );
      },

You're getting away with it because you're setting minimumVisitLength to { minimumVisitLength: 30, heartbeatDelay: 10, } which happens to be the second parameter passed into the snowplow() call in the same way as v3. heartbeat is undefined and ultimately gets ignored in v3.

So this boils down to it'll "probably" work with v3 but I can't guarentee it and I haven't tested everything. So your milage may vary.

Given this still uses the global window.snowplow under the hood. You can actually use the debugger plugin, just outside of the npm package. If you call the snippet above it still should work, you'll just have to make sure you call it after the @analytics plugin has loading the Snowplow plugin. Again this is unsupported but it should work.

window.snowplow('addPlugin', 
  "https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-debugger@latest/dist/index.umd.min.js",
  ["snowplowDebugger", "DebuggerPlugin"],
  [ 4 ] // 4 = Info logs
);

@markojak
Copy link
Author

markojak commented Aug 25, 2021

This is a really great and comprehensive response. I can confirm that I had a problem with v3 and following the @analytics/snowplow setup instructions until I added the minimumVisitLength but i did not know this was related to the versioning.

Do you have an ETA on the V3 release for @analytics/snowplow ?

In the meanwhile I think we are going to switch to a V2 tracker for production applications.

I can confirm that window.snowplow('addPlugin' is not working for our application
(We are using Typescript)

preact.module.js:14 Uncaught TypeError: window.snowplow is not a function
    at _.AppContext [as constructor] (AppContext.tsx:147)

@markojak
Copy link
Author

@paulboocock Hey Paul, do you have an idea of when this plug-in can be updated to accommodate v3 ?

It seems we are experiencing some issues where sumbit_form events are not being sent to the s3 bucket and I'm worried this is now related to using the v3 tracker

Would you advise to downgrade to v2 in the meanwhile ?

@paulboocock
Copy link
Contributor

I probably won't get to a release out until October in reality, mainly because I'm going on holiday for a little while in a week.

I would definitely suggest downgrading to v2 if using this plugin. There isn't any difference in terms of what can be tracking with the core tracker between v2 and v3, the main difference is the extensibility with plugins, which you can't use via this library at the moment.

@paulboocock
Copy link
Contributor

preact.module.js:14 Uncaught TypeError: window.snowplow is not a function
    at _.AppContext [as constructor] (AppContext.tsx:147)

window.snowplow is on your site as a global (I checked from the link you shared earlier using the developer console). This is a TypeScript error, you'll need to ensure you define snowplow as a global so you don't get the type errors.

To test, you should be able to use the developer console to inject it:
Screenshot 2021-08-26 at 10 29 29

@markojak markojak changed the title Loading Snowplow Plugins not included in sp.js (Debugger Plugin) Bump / Upgrade Snowplow to v3 (RENAMED) Sep 19, 2021
@markojak
Copy link
Author

Hi @paulboocock I'm renaming this issue as it's really just about bumping the v2 to v3 for GetAnalytics
Is there any way I can help you with this upgrade?

We are launching a live version with Snowplow built in during the next 1-2 weeks and it would bring great peace of mind to know we're not running a v3 snowplow where we should be running a v2.

We are already sponsoring this project - Happy to do whatever I can

@paulboocock
Copy link
Contributor

Hey @markojak
I'm slowly making my way towards getting to this. I've just returned from vacation this week, but I'm optimistic I can wrap up my earlier work next week and get a PR out.

@markojak
Copy link
Author

markojak commented Oct 7, 2021

Hey @paulboocock - Just checking in to see if you perhaps managed to do this yet?
How would I know this is done, so that I don't pester you?

@paulboocock
Copy link
Contributor

I made a little more progress last weekend but haven't quite finished it yet. Just trying to figure out the cleanest way to get the new plugins loaded in. I'll make sure to @ you here and back on the JS Tracker repository in the issue I left open, once an update is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants