mickey / videojs-ga

Google Analytics plugin for video.js
MIT License
138 stars 109 forks source link

sendbeacon "percentsPlayedInterval" instead of "percent" #32

Open Barri-G opened 7 years ago

Barri-G commented 7 years ago

Hi.

As a videojs user now I need to get some information about "percent played" on some of my websites.

I've tried your code and it works, but I think the way it sends the percent played is not the easiest way to understand the information; I mean, when somebody plays 10% I get 10 as a value on my analytics. But if the video continues playing and reach 20% then "percent" = 20 is sent, so analytics shows "30" (10+20). I think the script should send 10 always if "percentplayedinterval" is set to 10. I was thinking about changing this piece of code

  for percent in [0..99] by percentsPlayedInterval
      if percentPlayed >= percent && percent not in percentsAlreadyTracked

        if "start" in eventsToTrack && percent == 0 && percentPlayed > 0
          sendbeacon( 'start', true )
        else if "percentsPlayed" in eventsToTrack && percentPlayed != 0
          sendbeacon( 'percent played', true, percent)

to this:

  for percent in [0..99] by percentsPlayedInterval
      if percentPlayed >= percent && percent not in percentsAlreadyTracked

        if "start" in eventsToTrack && percent == 0 && percentPlayed > 0
          sendbeacon( 'start', true )
        else if "percentsPlayed" in eventsToTrack && percentPlayed != 0
          sendbeacon( 'percent played', true, percentsPlayedInterval)

but before doing it I'd like to know if I'm omitting anything important, because you chase to use "percent" instead of "percentsPlayedInterval" on "sendbeacon" and probably you have your reasons.

Thank you for your time and your great project.

devkinetic commented 7 years ago

Just my two cents. We set percentsPlayedInterval to 70 and setup goal in GA. Since anything above 51 will only be triggered once per video play.

chrisbbreuer commented 7 years ago

@devkinetic which VJS version do you use?

devkinetic commented 7 years ago

The latest, with https://github.com/mickey/videojs-ga/pull/33 applied.